﻿/*
Copyright Scand LLC http://www.scbr.com
This version of Software is free for using in non-commercial applications. For commercial use please contact info@scbr.com to obtain license
*/

globalActiveDHTMLGridObject = null;
String.prototype._dhx_trim = function(){
 return this.replace(/&nbsp;/g," ").replace(/(^[ \t]*)|([ \t]*$)/g,"");
}


dhtmlxArray=function(ar){return dhtmlXHeir((ar||new Array()),new _dhtmlxArray());};
_dhtmlxArray=function(){return this;};
_dhtmlxArray.prototype._dhx_find = function(pattern){
 for(var i=0;i<this.length;i++){
 if(pattern==this[i])
 return i;
}
 return -1;
}
_dhtmlxArray.prototype._dhx_delAt = function(ind){
 if(Number(ind)<0 || this.length==0)
 return false;
 for(var i=ind;i<this.length;i++){
 this[i]=this[i+1];
}
 this.length--;
}
_dhtmlxArray.prototype._dhx_insertAt = function(ind,value){
 this[this.length] = null;
 for(var i=this.length-1;i>=ind;i--){
 this[i] = this[i-1]
}
 this[ind] = value
}
_dhtmlxArray.prototype._dhx_removeAt = function(ind){
 for(var i=ind;i<this.length;i++){
 this[i] = this[i+1]
}
 this.length--;
}
_dhtmlxArray.prototype._dhx_swapItems = function(ind1,ind2){
 var tmp = this[ind1];
 this[ind1] = this[ind2]
 this[ind2] = tmp;
}

 
dhtmlXGridObject=function(id){
 if(dojo.render.html.ie)try{document.execCommand("BackgroundImageCache",false,true);}catch(e){}
 if(id){
 if(typeof(id)=='object'){
 this.entBox = id
 this.entBox.id = "cgrid2_"+(new Date()).getTime();
}else
 this.entBox = document.getElementById(id);
}else{
 this.entBox = document.createElement("DIV");
 this.entBox.id = "cgrid2_"+(new Date()).getTime();
}



 this._tttag=this._tttag||"rows";
 this._cttag=this._cttag||"cell";
 this._rttag=this._rttag||"row";

 var self = this;

 this._wcorr=0;
 this.nm = this.entBox.nm || "grid";
 this.cell = null;
 this.row = null;
 this.editor=null;
 this._f2kE=true;this._dclE=true;
 this.combos=new Array(0);
 this.defVal=new Array(0);
 this.rowsAr = new Array(0);
 this.rowsCol = new dhtmlxArray(0);
 
 this._maskArr=new Array(0);
 this.selectedRows = new dhtmlxArray(0);
 this.rowsBuffer = new Array(new dhtmlxArray(0),new dhtmlxArray(0));
 this.loadedKidsHash = null;
 this.UserData = new Array(0)

 

 this.styleSheet = document.styleSheets;
 this.entBox.className = "gridbox";
 this.entBox.style.width = this.entBox.getAttribute("width")||(window.getComputedStyle?window.getComputedStyle(this.entBox,null)["width"]:(this.entBox.currentStyle?this.entBox.currentStyle["width"]:0))|| "100%";
 this.entBox.style.height = this.entBox.getAttribute("height")||(window.getComputedStyle?window.getComputedStyle(this.entBox,null)["height"]:(this.entBox.currentStyle?this.entBox.currentStyle["height"]:0))|| "100%";
 
 this.entBox.style.cursor = 'default';
 this.entBox.onselectstart = function(){return false};
 this.obj = document.createElement("TABLE");
 this.obj.cellSpacing = 0;
 this.obj.cellPadding = 0;
 this.obj.style.width = "100%";
 this.obj.style.tableLayout = "fixed";
 this.obj.className = "obj";

 this.obj._rows=function(i){return this.rows[i+1];}
 this.obj._rowslength=function(){return this.rows.length-1;}

 this.hdr = document.createElement("TABLE");
 this.hdr.style.border="1px solid gray";
 this.hdr.cellSpacing = 0;
 this.hdr.cellPadding = 0;
 if((!dojo.render.html.opera)||(_OperaRv>=8.5))
 this.hdr.style.tableLayout = "fixed";
 this.hdr.className = "hdr";
 this.hdr.width = "100%";

 this.xHdr = document.createElement("TABLE");
 this.xHdr.cellPadding = 0;
 this.xHdr.cellSpacing = 0;
 var r = this.xHdr.insertRow(0)
 var c = r.insertCell(0);
 r.insertCell(1).innerHTML = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
 c.appendChild(this.hdr)
 this.objBuf = document.createElement("DIV");
 this.objBuf.appendChild(this.obj);
 this.entCnt = document.createElement("TABLE");
 this.entCnt.insertRow(0).insertCell(0)
 this.entCnt.insertRow(1).insertCell(0);



 this.entCnt.cellPadding = 0;
 this.entCnt.cellSpacing = 0;
 this.entCnt.width = "100%";
 this.entCnt.height = "100%";

 this.entCnt.style.tableLayout = "fixed";

 this.objBox = document.createElement("DIV");
 this.objBox.style.width = "100%";
 this.objBox.style.height = this.entBox.style.height;
 this.objBox.style.overflow = "auto";
 this.objBox.style.position = "relative";
 this.objBox.appendChild(this.objBuf);
 this.objBox.className = "objbox";


 this.hdrBox = document.createElement("DIV");
 this.hdrBox.style.width = "100%"
 if(((dojo.render.html.opera)&&(_OperaRv<9)))
 this.hdrSizeA=25;else this.hdrSizeA=200;

 this.hdrBox.style.height=this.hdrSizeA+"px";
 if(dojo.render.html.ie)
 this.hdrBox.style.overflowX="hidden";
 else
 this.hdrBox.style.overflow = "hidden";

 this.hdrBox.style.position = "relative";
 this.hdrBox.appendChild(this.xHdr);



 this.preloadImagesAr = new Array(0)

 this.sortImg = document.createElement("IMG")
 this.sortImg.style.display = "none";
 this.hdrBox.insertBefore(this.sortImg,this.xHdr)
 this.entCnt.rows[0].cells[0].vAlign="top";
 this.entCnt.rows[0].cells[0].appendChild(this.hdrBox);
 this.entCnt.rows[1].cells[0].appendChild(this.objBox);


 this.entBox.appendChild(this.entCnt);
 
 this.entBox.grid = this;
 this.objBox.grid = this;
 this.hdrBox.grid = this;
 this.obj.grid = this;
 this.hdr.grid = this;
 
 this.cellWidthPX = new Array(0);
 this.cellWidthPC = new Array(0);
 this.cellWidthType = this.entBox.cellwidthtype || "px";

 this.delim = this.entBox.delimiter || ",";
 this._csvDelim = ",";

 this.hdrLabels =(this.entBox.hdrlabels || "").split(",");
 this.columnIds =(this.entBox.columnids || "").split(",");
 this.columnColor =(this.entBox.columncolor || "").split(",");
 this.cellType = dhtmlxArray((this.entBox.cellstype || "").split(","));
 this.cellAlign =(this.entBox.cellsalign || "").split(",");
 this.initCellWidth =(this.entBox.cellswidth || "").split(",");
 this.fldSort =(this.entBox.fieldstosort || "").split(",")
 this.imgURL = this.entBox.imagesurl || "gridCfx/";
 this.isActive = false;
 this.isEditable = true;
 this.raNoState = this.entBox.ranostate || null;
 this.chNoState = this.entBox.chnostate || null;
 this.selBasedOn =(this.entBox.selbasedon || "cell").toLowerCase()
 this.selMultiRows = this.entBox.selmultirows || false;
 this.multiLine = this.entBox.multiline || false;
 this.noHeader = this.entBox.noheader || false;
 this.dynScroll = this.entBox.dynscroll || false;
 this.dynScrollPageSize = 0;
 this.dynScrollPos = 0;
 this.xmlFileUrl = this.entBox.xmlfileurl || "";
 this.recordsNoMore = this.entBox.infinitloading || true;;
 this.useImagesInHeader = false;
 this.pagingOn = false;
 
 this.rowsBufferOutSize = 0;
 
 this.onCheckbox=this.onEnter=this.onRowSelect=this.onEditCell = function(){return true;};
 dhtmlxEvent(window,"unload",function(){try{self.destructor();}catch(e){}});

 this.loadXMLString = function(xmlstr,afterCall){
 if(afterCall)this.xmlLoader.waitCall=afterCall;
 this.xmlLoader.loadXMLString(xmlstr);
 }
 
 
 this.loadXML = function(url,afterCall){
 if(this._dload){this._dload=url;this._askRealRows(null,afterCall);return true;};
 if(this._xmlaR)this.setXMLAutoLoading(url);

 if(url.indexOf("?")!=-1)
 var s = "&";
 else
 var s = "?";
 var obj = this;
 if(this.onXLS)this.onXLS(this);

 if(afterCall)this.xmlLoader.waitCall=afterCall;
 this.xmlLoader.loadXML(url+""+s+"rowsLoaded="+this.getRowsNum()+"&lastid="+this.getRowId(this.getRowsNum()-1));
}

 
 this.setSkin = function(name){
 this.entBox.className = "gridbox gridbox_"+name;
 switch(name){
 case "xp": this._srdh=22;this._sizeFix=1;break;
 case "gray": if((dojo.render.html.ie)&&(document.compatMode != "BackCompat"))this._srdh=22;
 this._sizeFix=1;
 this._borderFix=(dojo.render.html.ie?1:0);break;
}
}


 
 this.doLoadDetails = function(obj){
 var root = self.xmlLoader.getXMLTopNode(self._tttag)
 if(root.tagName!="DIV")
 if(!self.xmlLoader.xmlDoc.nodeName){
 self.parseXML(self.xmlLoader.xmlDoc.responseXML)
}else{
 self.parseXML(self.xmlLoader.xmlDoc)
}
 
 if(self.pagingOn)
 self.createPagingBlock()
}
 this.xmlLoader = new dtmlXMLLoaderObject(this.doLoadDetails,window,true,this.no_cashe);
 if(dojo.render.html.ie)this.preventIECashing(true);
 this.dragger=new dhtmlDragAndDropObject();

 
 
 this._doOnScroll = function(e,mode){
 if(this._onSCRL)this._onSCRL(this.objBox.scrollLeft,this.objBox.scrollTop);
 this.doOnScroll(e,mode);
}
 
 this.doOnScroll = function(e,mode){
 this.hdrBox.scrollLeft = this.objBox.scrollLeft;
 if(this.ftr)
 this.ftr.parentNode.scrollLeft = this.objBox.scrollLeft;
 this.setSortImgPos(null,true);
 if(mode)return;
 
 
 if(!this.pagingOn && this.objBox.scrollTop+this.hdrSizeA+this.objBox.offsetHeight>this.objBox.scrollHeight){
 if(this._xml_ready &&(this.objBox._oldScrollTop!=this.objBox.scrollTop)&& this.addRowsFromBuffer()){
 this.objBox.scrollTop = this.objBox.scrollHeight -(this.hdrSizeA+1+this.objBox.offsetHeight)
 this.objBox._oldScrollTop=this.objBox.scrollTop;
}
}

 if(this._dload){
 if(this._dLoadTimer)window.clearTimeout(this._dLoadTimer);
 this._dLoadTimer=window.setTimeout(function(){self._askRealRows();},500);
}
}
 
 this.attachToObject = function(obj){
 obj.appendChild(this.entBox)

}
 
 this.init = function(fl){

 this.editStop()
 
 this.lastClicked = null;
 this.resized = null;
 this.fldSorted = this.r_fldSorted = null;
 this.gridWidth = 0;
 this.gridHeight = 0;
 
 this.cellWidthPX = new Array(0);
 this.cellWidthPC = new Array(0);
 if(this.hdr.rows.length>0){
 this.clearAll(true);
}
 if(this.cellType._dhx_find("tree")!=-1){
 this.loadedKidsHash = new Hashtable();
 this.loadedKidsHash.put("hashOfParents",new Hashtable())
}

 var hdrRow = this.hdr.insertRow(0);
 for(var i=0;i<this.hdrLabels.length;i++){
 hdrRow.appendChild(document.createElement("TH"));
 hdrRow.childNodes[i]._cellIndex=i;
 hdrRow.childNodes[i].style.height="0px";
}
 if(dojo.render.html.ie)hdrRow.style.position="absolute";
 else hdrRow.style.height='auto';

 var hdrRow = this.hdr.insertRow(dojo.render.html.khtml?2:1);

 hdrRow._childIndexes=new Array();
 var col_ex=0;
 for(var i=0;i<this.hdrLabels.length;i++){
 hdrRow._childIndexes[i]=i-col_ex;

 if((this.hdrLabels[i]==this.splitSign)&&(i!=0)){
 if(dojo.render.html.khtml)
 hdrRow.insertCell(i-col_ex);
 hdrRow.cells[i-col_ex-1].colSpan=(hdrRow.cells[i-col_ex-1].colSpan||1)+1;
 hdrRow.childNodes[i-col_ex-1]._cellIndex++;
 col_ex++;
 hdrRow._childIndexes[i]=i-col_ex;
 continue;
}

 hdrRow.insertCell(i-col_ex);

 hdrRow.childNodes[i-col_ex]._cellIndex=i;
 hdrRow.childNodes[i-col_ex]._cellIndexS=i;
 this.setHeaderCol(i,this.hdrLabels[i]);
}
 if(col_ex==0)hdrRow._childIndexes=null;
 this._cCount=this.hdrLabels.length;

 if(dojo.render.html.ie)window.setTimeout(function(){self.setSizes();},1);

 
 if(!this.obj.firstChild)
 this.obj.appendChild(document.createElement("TBODY"));

 var tar=this.obj.firstChild;
 if(!tar.firstChild){
 tar.appendChild(document.createElement("TR"));
 tar=tar.firstChild;
 if(dojo.render.html.ie)tar.style.position="absolute";
 else tar.style.height='auto';

 for(var i=0;i<this.hdrLabels.length;i++){
 tar.appendChild(document.createElement("TH"));
 tar.childNodes[i].style.height="0px";
}
}


 this.setColumnIds()
 this._c_order=null;
 if(this.multiLine==-1)
 this.multiLine = true;
 if(this.multiLine != true)
 this.obj.className+=" row20px";

 
 
 
 this.sortImg.style.position = "absolute";
 this.sortImg.style.display = "none";
 this.sortImg.src = this.imgURL+"sort_desc.gif";
 this.sortImg.defLeft = 0;
 
 
 this.entCnt.rows[0].style.display = '' 
 if(this.noHeader){
 this.entCnt.rows[0].style.display = 'none';
}else{
 this.noHeader = false
}




 this.setSizes();

 this.attachHeader();
 this.attachHeader(0,0,"_aFoot");

 if(fl)
 this.parseXML()
 this.obj.scrollTop = 0

 if(this.dragAndDropOff)this.dragger.addDragLanding(this.entBox,this);
 if(this._initDrF)this._initD();

};
 
 this.setSizes = function(fl){
 if((!this.noHeader)&&((!this.hdr.rows[0])||(!this.hdrBox.offsetWidth)))return;
 if(fl && this.gridWidth==this.entBox.offsetWidth && this.gridHeight==this.entBox.offsetHeight){
 return false
}else if(fl){
 this.gridWidth = this.entBox.offsetWidth
 this.gridHeight = this.entBox.offsetHeight
}


 if((!this.hdrBox.offsetHeight)&&(this.hdrBox.offsetHeight>0))
 this.entCnt.rows[0].cells[0].height = this.hdrBox.offsetHeight+"px";

 var gridWidth = parseInt(this.entBox.offsetWidth);
 var gridHeight = parseInt(this.entBox.offsetHeight)-((!dojo.render.html.ie)?(this._sizeFix||0):0);



 var _isVSroll=(this.objBox.scrollHeight>this.objBox.offsetHeight);
 if(((!this._ahgr)&&(_isVSroll))||((this._ahgrM)&&(this._ahgrM<this.objBox.scrollHeight)))
 gridWidth-=(this._scrFix||(dojo.render.html.moz?19:16));





 var len = this.hdr.rows[0].cells.length
 

 for(var i=0;i<this._cCount;i++){
 if(this.cellWidthType=='px' && this.cellWidthPX.length < len){
 this.cellWidthPX[i] = this.initCellWidth[i] - this._wcorr;
}else if(this.cellWidthType=='%' && this.cellWidthPC.length < len){
 this.cellWidthPC[i] = this.initCellWidth[i];
}
 if(this.cellWidthPC.length!=0){
 this.cellWidthPX[i] = parseInt(gridWidth*this.cellWidthPC[i]/100);
}
}

 var wcor=this.entBox.offsetWidth-this.entBox.clientWidth;

 var summ = 0;
 var fcols=new Array();

 for(var i=0;i<this._cCount;i++)
 if((this.initCellWidth[i]=="*")&&((!this._hrrar)||(!this._hrrar[i])))
 fcols[fcols.length]=i;
 else
 summ+= parseInt(this.cellWidthPX[i]);
 if(fcols.length){
 var ms=Math.floor((gridWidth-summ-1-wcor)/fcols.length);
 if(ms<0)ms=1;
 for(var i=0;i<fcols.length;i++){
 var min=(this._drsclmW?this._drsclmW[fcols[i]]:0);
 this.cellWidthPX[fcols[i]]=(min?(min>ms?min:ms):ms)-this._wcorr;
 summ+=ms;
}
}

 this.chngCellWidth();



 var summ = 0;
 for(var i=0;i<this._cCount;i++)
 summ+= parseInt(this.cellWidthPX[i])
 if(dojo.render.html.opera)summ-=1;

 this.objBuf.style.width = summ+"px";
 if((this.ftr)&&(!this._realfake))
 this.ftr.style.width = summ+"px";

 this.objBuf.childNodes[0].style.width = summ+"px";
 
 
 this.doOnScroll(0,1);

 
 

 this.hdr.style.border="0px solid gray";
 
 var zheight=this.hdr.offsetHeight+(this._borderFix?this._borderFix:0);
 if(this.ftr)zheight+=this.ftr.offsetHeight;

 if(this._ahgr)
 if(this.objBox.scrollHeight){
 if(dojo.render.html.ie)
 var z2=this.objBox.scrollHeight;
 else
 var z2=this.objBox.childNodes[0].scrollHeight;
 var scrfix=((this.objBox.offsetWidth<this.objBox.scrollWidth)?(dojo.render.html.moz?20:18):1);
 if(this._ahgrMA)
 z2=this.entBox.parentNode.offsetHeight-zheight-scrfix;


 if(((this._ahgrM)&&((this._ahgrF?(z2+zheight+scrfix):z2)>this._ahgrM)))
 gridHeight=this._ahgrM*1+(this._ahgrF?0:(zheight+scrfix));
 else
 gridHeight=z2+zheight+scrfix;

 this.entBox.style.height=gridHeight+"px";
}

 if(this.ftr)zheight-=this.ftr.offsetHeight;

 var aRow=this.entCnt.rows[1].cells[0].childNodes[0];
 if(!this.noHeader)
 aRow.style.top =(zheight-this.hdrBox.offsetHeight+(dojo.render.html.moz?0:(-wcor)))+"px";

 
 aRow.style.height =(((gridHeight - zheight-1)<0 && dojo.render.html.ie)?20:(gridHeight - zheight-1))-(this.ftr?this.ftr.offsetHeight:0)+"px";
 if(this.ftr)this.entCnt.style.height=this.entBox.offsetHeight-this.ftr.offsetHeight+"px";

 if(this._dload)
 this._dloadSize=Math.floor(parseInt(this.entBox.style.height)/20)+2;

};

 
 this.chngCellWidth = function(){
 if((dojo.render.html.opera)&&(this.ftr))
 this.ftr.width=this.objBox.scrollWidth+"px";
 var l=this._cCount;
 for(var i=0;i<l;i++){
 this.hdr.rows[0].cells[i].style.width = this.cellWidthPX[i]+"px";
 this.obj.rows[0].childNodes[i].style.width = this.cellWidthPX[i]+"px";
 if(this.ftr)
 this.ftr.rows[0].cells[i].style.width = this.cellWidthPX[i]+"px";
}
}
 
 this.setDelimiter = function(delim){
 this.delim = delim;
}
 
 this.setInitWidthsP = function(wp){
 this.cellWidthType = "%";
 this.initCellWidth = wp.split(this.delim.replace(/px/gi,""));
 var el=window;
 var self=this;
 if(el.addEventListener){
 if((dojo.render.html.moz)&&(_FFrv<1.8))
 el.addEventListener("resize",function(){
 if(!self.entBox)return;
 var z=self.entBox.style.width;
 self.entBox.style.width="1px";

 window.setTimeout(function(){self.entBox.style.width=z;self.setSizes();},10);
},false);
 else
 el.addEventListener("resize",function(){if(self.setSizes)self.setSizes();},false);
}
 else if(el.attachEvent)
 el.attachEvent("onresize",function(){
 if(self._resize_timer)window.clearTimeout(self._resize_timer);
 if(self.setSizes)
 self._resize_timer=window.setTimeout(function(){self.setSizes();},500);
});

}
 
 this.setInitWidths = function(wp){
 this.cellWidthType = "px";
 this.initCellWidth = wp.split(this.delim);
 if(dojo.render.html.moz){
 for(var i=0;i<this.initCellWidth.length;i++)
 if(this.initCellWidth[i]!="*")
 this.initCellWidth[i]=parseInt(this.initCellWidth[i])-2;
}

}

 
 this.enableMultiline = function(state){
 this.multiLine = convertStringToBoolean(state);
}

 
 this.enableMultiselect = function(state){
 this.selMultiRows = convertStringToBoolean(state);
}

 
 this.setImagePath = function(path){
 this.imgURL = path;
}

 
 this.changeCursorState = function(ev){
 var el = ev.target||ev.srcElement;
 if(el.tagName!="TD")
 el = this.getFirstParentOfType(el,"TD")
 if((el.tagName=="TD")&&(this._drsclmn)&&(!this._drsclmn[el._cellIndex]))return;
 var check = ev.layerX+(((!dojo.render.html.ie)&&(el.tagName=="DIV"))?el.offsetLeft:0);
 if((el.offsetWidth -(ev.offsetX||(parseInt(this.getPosition(el,this.hdrBox))-check)*-1))<10){
 el.style.cursor = "E-resize";
}else
 el.style.cursor = "default";
 if(dojo.render.html.opera)this.hdrBox.scrollLeft = this.objBox.scrollLeft;
}
 
 this.startColResize = function(ev){
 this.resized = null;
 var el = ev.target||ev.srcElement;
 if(el.tagName!="TD")
 el = this.getFirstParentOfType(el,"TD")
 var x = ev.clientX;
 var tabW = this.hdr.offsetWidth;
 var startW = parseInt(el.offsetWidth)
 if(el.tagName=="TD" && el.style.cursor!="default"){
 if((this._drsclmn)&&(!this._drsclmn[el._cellIndex]))return;
 this.entBox.onmousemove = function(e){this.grid.doColResize(e||window.event,el,startW,x,tabW)}
 document.body.onmouseup = new Function("","document.getElementById('"+this.entBox.id+"').grid.stopColResize()");
}
}
 
 this.stopColResize = function(){
 this.entBox.onmousemove = "";
 document.body.onmouseup = "";
 this.setSizes();
 this.doOnScroll(0,1)
 if(this.onRSE)this.onRSE(this);
}
 
 this.doColResize = function(ev,el,startW,x,tabW){
 el.style.cursor = "E-resize";
 this.resized = el;
 var fcolW = startW+(ev.clientX-x);
 var wtabW = tabW+(ev.clientX-x)
 if((this.onRSI)&&(!this.onRSI(el._cellIndex,fcolW,this)))return;
 if(el.colSpan>1){
 var a_sizes=new Array();
 for(var i=0;i<el.colSpan;i++)
 a_sizes[i]=Math.round(fcolW*this.hdr.rows[0].childNodes[el._cellIndexS+i].offsetWidth/el.offsetWidth);
 for(var i=0;i<el.colSpan;i++)
 this._setColumnSizeR(el._cellIndexS+i*1,a_sizes[i]);
}
 else
 this._setColumnSizeR(el._cellIndex,fcolW);
 this.doOnScroll(0,1);
 if(dojo.render.html.opera)this.setSizes();
 this.objBuf.childNodes[0].style.width = "";
}

 
 this._setColumnSizeR=function(ind,fcolW){
 if(fcolW>(this._drsclmW?(this._drsclmW[ind]||10):10)){
 this.obj.firstChild.firstChild.childNodes[ind].style.width = fcolW+"px";
 this.hdr.rows[0].childNodes[ind].style.width = fcolW+"px";
 if(this.ftr)
 this.ftr.rows[0].childNodes[ind].style.width = fcolW+"px";
 if(this.cellWidthType=='px'){
 this.cellWidthPX[ind]=fcolW;
}else{
 var gridWidth = parseInt(this.entBox.offsetWidth);
 if(this.objBox.scrollHeight>this.objBox.offsetHeight)
 gridWidth-=(this._scrFix||(dojo.render.html.moz?19:16));
 var pcWidth = Math.round(fcolW/gridWidth*100)
 this.cellWidthPC[ind]=pcWidth;
}
}
}
 
 this.setSortImgState=function(state,ind,direction,row){
 if(!convertStringToBoolean(state)){
 this.sortImg.style.display = "none";
 return;
}

 if(direction=="ASC")
 this.sortImg.src = this.imgURL+"sort_asc.gif";
 else
 this.sortImg.src = this.imgURL+"sort_desc.gif";
 this.sortImg.style.display="";
 this.fldSorted=this.hdr.rows[0].cells[ind];
 this.r_fldSorted=this.hdr.rows[row||1].cells[ind];

 this.setSortImgPos(ind);
}

 
 this.setSortImgPos = function(ind,mode,hRowInd,el){
 if(!el){
 if(!ind)
 var el = this.r_fldSorted;
 else
 var el = this.hdr.rows[hRowInd||0].cells[ind];
}

 if(el!=null){
 var pos = this.getPosition(el,this.hdrBox)
 var wdth = el.offsetWidth;
 this.sortImg.style.left = Number(pos[0]+wdth-13)+"px";
 this.sortImg.defLeft = parseInt(this.sortImg.style.left)
 this.sortImg.style.top = Number(pos[1]+5)+"px";

 if((!this.useImagesInHeader)&&(!mode))
 this.sortImg.style.display = "inline";
 this.sortImg.style.left = this.sortImg.defLeft+"px";
}
}

 
 this.setActive = function(fl){
 if(arguments.length==0)
 var fl = true;
 if(fl==true){
 
 if(globalActiveDHTMLGridObject &&(globalActiveDHTMLGridObject != this))
 globalActiveDHTMLGridObject.editStop();

 globalActiveDHTMLGridObject = this;
 this.isActive = true;
}else{
 this.isActive = false;
}
};
 
 this._doClick = function(ev){
 var selMethod = 0;
 var el = this.getFirstParentOfType(dojo.render.html.ie?ev.srcElement:ev.target,"TD");
 var fl = true;
 if(this.selMultiRows!=false){
 if(ev.shiftKey && this.row!=null){
 selMethod = 1;
}
 if(ev.ctrlKey){
 selMethod = 2;
}

}
 this.doClick(el,fl,selMethod)
};


 
 this._doContClick=function(ev){
 var el = this.getFirstParentOfType(dojo.render.html.ie?ev.srcElement:ev.target,"TD");
 if((!el)||(el.parentNode.idd===undefined))return true;
 //if(ev.button==2){ 修正遨游下不能正常绑定右键事件——遨游下，邮件button键值为0
 if(ev.button==2||ev.button==0){
 if((this.onRCL)&&(!this.onRCL(el.parentNode.idd,el._cellIndex,ev))){
 var z=function(e){document.body.oncontextmenu=Function("return true;");(e||event).cancelBubble=true;return false;}
 if(dojo.render.html.ie)ev.srcElement.oncontextmenu=z;
 else document.body.oncontextmenu=z;

 return false;
}
 if(this._ctmndx){
 if((this.onBCM)&&(!this.onBCM(el.parentNode.idd,el._cellIndex,this)))return true;
 el.contextMenuId=el.parentNode.idd+"_"+el._cellIndex;
 el.contextMenu=this._ctmndx;
 el.a=this._ctmndx._contextStart;
 if(dojo.render.html.ie)
 ev.srcElement.oncontextmenu = function(){event.cancelBubble=true;return false;};
 el.a(el,ev);
 el.a=null;
}
}
 else
 if(this._ctmndx)this._ctmndx._contextEnd();
 return true;
}

 
 this.doClick = function(el,fl,selMethod){

 var psid=this.row?this.row.idd:0;

 this.setActive(true);
 if(!selMethod)
 selMethod = 0;
 if(this.cell!=null)
 this.cell.className = this.cell.className.replace(/cellselected/g,"");
 if(el.tagName=="TD" &&(this.rowsCol._dhx_find(this.rowsAr[el.parentNode.idd])!=-1 || this.rowsBuffer[0]._dhx_find(el.parentNode.idd)!=-1)){
 if(this.onSSC)var initial=this.getSelectedId();
 var prow=this.row;
 if(selMethod==0){
 this.clearSelection();
}else if(selMethod==1){
 var elRowIndex = this.rowsCol._dhx_find(el.parentNode)
 var lcRowIndex = this.rowsCol._dhx_find(this.lastClicked)
 if(elRowIndex>lcRowIndex){
 var strt = lcRowIndex;
 var end = elRowIndex;
}else{
 var strt = elRowIndex;
 var end = lcRowIndex;
}
 this.clearSelection();
 for(var i=0;i<this.rowsCol.length;i++){
 if((i>=strt && i<=end)&&(this.rowsCol[i])&&(!this.rowsCol[i]._sRow)){
 if((!this.onBFS)||(this.onBFS(this.rowsCol[i].idd,psid))){
 this.rowsCol[i].className+=" rowselected";
 this.selectedRows[this.selectedRows.length] = this.rowsCol[i]
}
}
}

}else if(selMethod==2){
 if(el.parentNode.className.indexOf("rowselected")!= -1){
 el.parentNode.className=el.parentNode.className.replace("rowselected","");
 this.selectedRows._dhx_removeAt(this.selectedRows._dhx_find(el.parentNode))
 var skipRowSelection = true;
}
}
 this.editStop()
 this.cell = el;

 if((prow == el.parentNode)&&(this._chRRS))
 fl=false;

 this.row = el.parentNode;

 if((!skipRowSelection)&&(!this.row._sRow)){
 if((!this.onBFS)||(this.onBFS(this.row.idd,psid))){
 this.row.className+= " rowselected"
 if(this.selectedRows._dhx_find(this.row)==-1)
 this.selectedRows[this.selectedRows.length] = this.row;
}
 else this.row=prow;

}
 if(this.selBasedOn=="cell"){
 if(this.cell.parentNode.className.indexOf("rowselected")!=-1)
 this.cell.className = this.cell.className.replace(/cellselected/g,"")+" cellselected";
}

 if(selMethod!=1)
 this.lastClicked = el.parentNode;

 var rid = this.row.idd;
 var cid = this.cell.cellIndex;
 if(fl)setTimeout(function(){self.onRowSelect(rid,cid);},100)
 if(this.onSSC){
 var afinal=this.getSelectedId();
 if(initial!=afinal)this.onSSC(afinal);
}
}
 this.isActive = true;
 this.moveToVisible(this.cell)
}
 
 this.selectCell = function(r,cInd,fl,preserve,edit){
 if(!fl)
 fl = false;
 if(typeof(r)!="object")
 r = this.rowsCol[r]

 var c = r.childNodes[cInd];
 if(preserve)
 this.doClick(c,fl,3)
 else
 this.doClick(c,fl)
 if(edit)this.editCell();
}
 
 this.moveToVisible = function(cell_obj,onlyVScroll){
 try{
 var distance = cell_obj.offsetLeft+cell_obj.offsetWidth+20;

 if(distance>(this.objBox.offsetWidth+this.objBox.scrollLeft)){
 var scrollLeft = distance - this.objBox.offsetWidth;
}else if(cell_obj.offsetLeft<this.objBox.scrollLeft){
 var scrollLeft = cell_obj.offsetLeft-5
}
 if((scrollLeft)&&(!onlyVScroll))
 this.objBox.scrollLeft = scrollLeft;

 var distance = cell_obj.offsetTop+cell_obj.offsetHeight+20;
 if(distance>(this.objBox.offsetHeight+this.objBox.scrollTop)){
 var scrollTop = distance - this.objBox.offsetHeight;
}else if(cell_obj.offsetTop<this.objBox.scrollTop){
 var scrollTop = cell_obj.offsetTop-5
}
 if(scrollTop)
 this.objBox.scrollTop = scrollTop;
}catch(er){
}
}
 
 this.editCell = function(){
 this.editStop();
 if((this.isEditable!=true)||(!this.cell))
 return false;
 var c = this.cell;
 
 if(c.parentNode._locked)return false;
 

 this.editor = this.cells4(c);

 
 if(this.editor!=null){
 if(this.editor.isDisabled()){this.editor=null;return false;}
 c.className+=" editable";

 if(this.onEditCell(0,this.row.idd,this.cell._cellIndex)!=false){
 this._Opera_stop=(new Date).valueOf();
 this.editor.edit()
 this.onEditCell(1,this.row.idd,this.cell._cellIndex)
}else{
 this.editor=null;
}
}
}
 
 this.editStop = function(){
 if(dojo.render.html.opera)
 if(this._Opera_stop){
 if((this._Opera_stop*1+50)>(new Date).valueOf())return;
 this._Opera_stop=null;
}

 if(this.editor && this.editor!=null){
 this.cell.className=this.cell.className.replace("editable","");
 if(this.editor.detach())this.cell.wasChanged = true;

 var g=this.editor;
 this.editor=null;
 var z=this.onEditCell(2,this.row.idd,this.cell._cellIndex,g.getValue(),g.val);
 if((typeof(z)=="string")||(typeof(z)=="number"))
 g.setValue(z);
 else
 if(!z)g.setValue(g.val);
}
}

 this._getNextCell=function(acell){
 acell=acell||this.cell;
 arow=this.cell.parentNode;

 if(acell.nextSibling)
 acell=acell.nextSibling;
 else{
 arow=this.rowsCol[this.rowsCol._dhx_find(arow)+1];
 if(!arow)
 return null;
 acell=arow.childNodes[0];
}
 if(acell.style.display!="none")
 return acell;
 return this._getNextCell(acell);
}
 this._getPrevCell=function(acell){
 acell=acell||this.cell;
 arow=this.cell.parentNode;

 if(acell.previousSibling)
 acell=acell.previousSibling;
 else{
 arow=this.rowsCol[this.rowsCol._dhx_find(arow)-1];
 if(!arow)
 return null;
 acell=arow.childNodes[arow.childNodes.length-1];
}
 if(acell.style.display!="none")
 return acell;
 return this._getPrevCell(acell);
}

 
 this.doKey = function(ev){
 if(!ev)return true;
 if((ev.target||ev.srcElement).value!==window.undefined){
 var zx=(ev.target||ev.srcElement);
 if((!zx.parentNode)||(zx.parentNode.className.indexOf("editable")==-1))
 return true;
}
 if((globalActiveDHTMLGridObject)&&(this!=globalActiveDHTMLGridObject))
 return globalActiveDHTMLGridObject.doKey(ev);
 if(this.isActive==false){
 
 return true;
}

 if(this._htkebl)return true;
 if((this.onKPR)&&(!this.onKPR(ev.keyCode,ev.ctrlKey,ev.shiftKey)))return false;
 try{
 var type = this.cellType[this.cell._cellIndex]
 
 if(ev.keyCode==13 &&(ev.ctrlKey || ev.shiftKey)){
 var rowInd = this.rowsCol._dhx_find(this.row)
 if(window.event.ctrlKey && rowInd!=this.rowsCol.length-1){
 if(this.row.rowIndex==this.obj._rowslength()-1 && this.dynScroll && this.dynScroll!='false')
 this.doDynScroll("dn")
 this.selectCell(this.rowsCol[rowInd+1],this.cell._cellIndex,true);
}else if(ev.shiftKey && rowInd!=0){
 if(this.row.rowIndex==0 && this.dynScroll && this.dynScroll!='false')
 this.doDynScroll("up")
 this.selectCell(this.rowsCol[rowInd-1],this.cell._cellIndex,true);
}
 dojo.render.html.ie?ev.returnValue=false:ev.preventDefault();
}
 if(ev.keyCode==13 && !ev.ctrlKey && !ev.shiftKey){
 this.editStop();
 this.onEnter(this.row.idd,this.cell._cellIndex);
 dojo.render.html.ie?ev.returnValue=false:ev.preventDefault();
}
 
 if(ev.keyCode==9){
 this.editStop();
 if(ev.shiftKey)
 var z=this._getPrevCell();
 else
 var z=this._getNextCell();
 if(!z)return true;
 this.selectCell(z.parentNode,z._cellIndex,(this.row!=z.parentNode));
 this.editCell()
 dojo.render.html.ie?ev.returnValue=false:ev.preventDefault();
}
 
 if(ev.keyCode==40 || ev.keyCode==38){

 if(this.editor && this.editor.combo){
 if(ev.keyCode==40)this.editor.shiftNext();
 if(ev.keyCode==38)this.editor.shiftPrev();
 return false;
}
 else{
 var rowInd = this.row.rowIndex;
 if(ev.keyCode==38 && rowInd!=1){
 
 
 this.selectCell(this.obj._rows(rowInd-2),this.cell._cellIndex,true);
}else if(this.pagingOn && ev.keyCode==38 && rowInd==1 && this.currentPage!=1){
 this.changePage(this.currentPage-1)
 this.selectCell(this.obj.rows[this.obj.rows.length-1],this.cell._cellIndex,true);
}else if(ev.keyCode==40 && rowInd!=this.rowsCol.length && rowInd!=this.obj.rows.length-1){
 
 
 this.selectCell(this.obj._rows(rowInd),this.cell._cellIndex,true);
}else if(this.pagingOn && ev.keyCode==40 &&(this.row!=this.rowsCol[this.rowsCol.length-1] || this.rowsBuffer[0].length>0 || !this.recordsNoMore)){
 this.changePage(this.currentPage+1)
 this.selectCell(this.obj._rows(0),this.cell._cellIndex,true);
}
}
 dojo.render.html.ie?ev.returnValue=false:ev.preventDefault();

}
 
 if((ev.keyCode==113)&&(this._f2kE)){
 this.editCell();
 return false;
}
 
 if(ev.keyCode==32){
 var c = this.cell
 var ed = this.cells4(c);
 if(ed.changeState()!=false)
 dojo.render.html.ie?ev.returnValue=false:ev.preventDefault();
}
 
 if(ev.keyCode==27 && this.oe!=false){
 this.editStop();
 dojo.render.html.ie?ev.returnValue=false:ev.preventDefault();
}
 
 if(ev.keyCode==33 || ev.keyCode==34){
 if(this.pagingOn){
 if(ev.keyCode==33){
 this.changePage(this.currentPage-1)
}else{
 this.changePage(this.currentPage+1)
}
}
 var new_ind=Math.floor((this.getRowIndex(this.row.idd)||0)+(ev.keyCode!=33?1:-1)*this.objBox.offsetHeight/(this._srdh||20));
 if(new_ind<0)new_ind=0;
 if(new_ind>=this.rowsCol.length)new_ind=this.rowsCol.length-1;
 this.selectCell(new_ind,this.cell._cellIndex,true);

 dojo.render.html.ie?ev.returnValue=false:ev.preventDefault();
}
 
 if(!this.editor)
{
 if(ev.keyCode==37 && this.cellType._dhx_find("tree")!=-1){
 this.collapseKids(this.row)
 dojo.render.html.ie?ev.returnValue=false:ev.preventDefault();
}
 if(ev.keyCode==39 && this.cellType._dhx_find("tree")!=-1){
 this.expandKids(this.row)
 dojo.render.html.ie?ev.returnValue=false:ev.preventDefault();
}
}
 return true;
}catch(er){return true;}


}
 
 this.getRow = function(cell){
 if(!cell)
 cell = window.event.srcElement;
 if(cell.tagName!='TD')
 cell = cell.parentElement;
 r = cell.parentElement;
 if(this.cellType[cell._cellIndex]=='lk')
 eval(this.onLink+"('"+this.getRowId(r.rowIndex)+"',"+cell._cellIndex+")");
 this.selectCell(r,cell._cellIndex,true)
}
 
 this.selectRow = function(r,fl,preserve){
 if(typeof(r)!='object')
 r = this.rowsCol[r]
 this.selectCell(r,0,fl,preserve)
};
 
 this.sortRows = function(col,type,order){
 while(this.addRowsFromBuffer(true));
 
 if(this.cellType._dhx_find("tree")!=-1){
 return this.sortTreeRows(col,type,order)
}
 var self=this;
 var arrTS=new Array();
 var atype = this.cellType[col];
 var amet="getValue";
 if(atype=="link")amet="getContent";

 for(var i=0;i<this.rowsCol.length;i++)
 arrTS[this.rowsCol[i].idd]=this.cells3(this.rowsCol[i],col)[amet]();

 this._sortRows(col,type,order,arrTS);
}

 
 this._sortRows = function(col,type,order,arrTS){
 var sort="sort";
 if(this._sst)sort="stablesort";



 if(type=='str'){
 this.rowsCol[sort](function(a,b){
 if(order=="asc")
 return arrTS[a.idd]>arrTS[b.idd]?1:-1
 else
 return arrTS[a.idd]<arrTS[b.idd]?1:-1
});
}else if(type=='int'){
 this.rowsCol[sort](function(a,b){
 var aVal = parseFloat(arrTS[a.idd]);aVal=isNaN(aVal)?-99999999999999:aVal;
 var bVal = parseFloat(arrTS[b.idd]);bVal=isNaN(bVal)?-99999999999999:bVal;
 if(order=="asc")
 return aVal-bVal;
 else
 return bVal-aVal;

});
}else if(type=='date'){
 this.rowsCol[sort](function(a,b){
 var aVal = Date.parse(arrTS[a.idd])||(Date.parse("01/01/1900"));
 var bVal = Date.parse(arrTS[b.idd])||(Date.parse("01/01/1900"));
 if(order=="asc")
 return aVal-bVal
 else
 return bVal-aVal

});
}
 if(this.dynScroll && this.dynScroll!='false'){
 alert("not implemented yet")
}else if(this.pagingOn){
 this.changePage(this.currentPage);
 if(this.onGridReconstructed)this.onGridReconstructed();
}else{
 var tb = this.obj.firstChild;
 if(tb.tagName == 'TR')tb = this.obj;


 for(var i=0;i<this.rowsCol.length;i++){
 if(this.rowsCol[i]!=this.obj._rows(i))
 tb.insertBefore(this.rowsCol[i],this.obj._rows(i))
 
}
}
 
 if(this.onGridReconstructed)this.onGridReconstructed();
}


 
 this.setXMLAutoLoading = function(filePath,bufferSize){
 if(arguments.length==0)return(this._xmlaR=true);
 this.recordsNoMore = false;
 this.xmlFileUrl = filePath;
 this.rowsBufferOutSize = bufferSize||this.rowsBufferOutSize==0?40:this.rowsBufferOutSize;
}

 
 this.enableBuffering = function(bufferSize){
 this.rowsBufferOutSize = bufferSize||(this.rowsBufferOutSize==0?40:this.rowsBufferOutSize);
}




 
 this.addRowsFromBuffer = function(stopBeforeServerCall){
 if(this.rowsBuffer[0].length==0){
 if(!this.recordsNoMore && !stopBeforeServerCall){
 if((this.xmlFileUrl!="")&&(!this._startXMLLoading)){
 this._startXMLLoading=true;
 this.loadXML(this.xmlFileUrl)
}
}else
 return false;
}
 var cnt = Math.min(this.rowsBufferOutSize,this.rowsBuffer[0].length)


 
 for(var i=0;i<cnt;i++){
 
 if(this.rowsBuffer[1][0].tagName == "TR"){
 this._insertRowAt(this.rowsBuffer[1][0],-1,this.pagingOn);
}else{
 var rowNode = this.rowsBuffer[1][0]
 this._insertRowAt(this.createRowFromXMLTag(rowNode),-1,this.pagingOn);
}
 this.rowsBuffer[0]._dhx_removeAt(0);
 this.rowsBuffer[1]._dhx_removeAt(0);
}

 return this.rowsBuffer[0].length!=0;
}
 
 this.createRowFromXMLTag = function(rowNode){
 if(rowNode.tagName=="TR")
 return rowNode;

 var tree=this.cellType._dhx_find("tree");
 var rId = rowNode.getAttribute("id")

 this.rowsAr[rId] = this._prepareRow(rId);
 var r= this._fillRowFromXML(this.rowsAr[rId],rowNode,tree,null);
 
 return r;
}

 
 this.setMultiselect = function(fl){
 this.selMultiRows = convertStringToBoolean(fl);
}

 
 this.wasDblClicked = function(ev){
 var el = this.getFirstParentOfType(dojo.render.html.ie?ev.srcElement:ev.target,"TD");
 if(el){
 var rowId = el.parentNode.idd;
 return((this.onRowDblClicked)?this.onRowDblClicked(rowId,el._cellIndex):true);
}
}

 
 this._onHeaderClick = function(e){
 var that=this.grid;
 var el = that.getFirstParentOfType(dojo.render.html.ie?event.srcElement:e.target,"TD");

 if((this.grid.onHeaderClick)&&(!this.grid.onHeaderClick(el._cellIndexS,(e||event))))return false;
 if(this.grid.resized==null)
 that.sortField(el._cellIndexS,false,el)
}

 
 this.deleteSelectedItem = function(){
 var num = this.selectedRows.length 
 if(num==0)
 return;
 var tmpAr = this.selectedRows;
 this.selectedRows = new dhtmlxArray(0)
 for(var i=num-1;i>=0;i--){
 var node = tmpAr[i]

 if(!this.deleteRow(node.idd,node)){
 this.selectedRows[this.selectedRows.length] = node;
}else{
 if(node==this.row){
 var ind = i;
}
}
 
}
 if(ind){
 try{
 if(ind+1>this.rowsCol.length)
 ind--;
 this.selectCell(ind,0,true)
}catch(er){
 this.row = null
 this.cell = null
}
}
}

 
 this.getSelectedId = function(){
 var selAr = new Array(0);
 for(var i=0;i<this.selectedRows.length;i++){
 selAr[selAr.length]=this.selectedRows[i].idd
}

 
 if(selAr.length==0)
 return null;
 else
 return selAr.join(this.delim);
}
 
 this.getSelectedCellIndex = function(){
 if(this.cell!=null)
 return this.cell._cellIndex;
 else
 return -1;
}
 
 this.getColWidth = function(ind){
 return parseInt(this.cellWidthPX[ind])+((dojo.render.html.moz)?2:0);
}

 
 this.setColWidth = function(ind,value){
 if(this.cellWidthType=='px')
 this.cellWidthPX[ind]=parseInt(value);
 else
 this.cellWidthPC[ind]=parseInt(value);
 this.setSizes();
}


 
 this.getRowById = function(id){
 var row = this.rowsAr[id]
 if(row)
 return row;
 else
 if(this._dload){
 var ind = this.rowsBuffer[0]._dhx_find(id);
 if(ind>=0){
 this._askRealRows(ind);
 return this.getRowById(id);
}
}
 else if(this.pagingOn){
 var ind = this.rowsBuffer[0]._dhx_find(id);
 if(ind>=0){
 var r = this.createRowFromXMLTag(this.rowsBuffer[1][ind]);
 this.rowsBuffer[1][ind] = r;
 return r;
}else{
 return null;
}
}
 else if(this._slowParse)
 return this._seekAndDeploy(id);
 return null;
}
 
 this.getRowByIndex = function(ind){
 if(this.rowsCol.length<=ind){
 if((this.rowsCol.length+this.rowsBuffer[0].length)<=ind)
 return null;
 else{
 var indInBuf = ind-this.rowsCol.length-1;
 var r = this.createRowFromXMLTag(this.rowsBuffer[1][indInBuf]);
 return r;
}
}else{
 return this.rowsCol[ind]
}
}

 
 this.getRowIndex = function(row_id){
 var ind = this.rowsCol._dhx_find(this.getRowById(row_id));
 if(ind!=-1)
 return ind;
 else{
 ind = this.rowsBuffer[0]._dhx_find(row_id)
 if(ind!=-1)
 return ind+this.rowsCol.length;
 return -1;
}
}
 
 this.getRowId = function(ind){
 var z=this.rowsCol[parseInt(ind)];
 if(z)return z.idd;
 return(this.rowsBuffer[0][this._dload?ind:(ind-this.rowsCol.length-1)]||null);
}
 
 this.setRowId = function(ind,row_id){
 var r = this.rowsCol[ind]
 this.changeRowId(r.idd,row_id)
}
 
 this.changeRowId = function(oldRowId,newRowId){
 var row = this.rowsAr[oldRowId]
 row.idd = newRowId;
 if(this.UserData[oldRowId]){
 this.UserData[newRowId] = this.UserData[oldRowId]
 this.UserData[oldRowId] = null;
}
 if(this.loadedKidsHash){
 var oldHash=this.loadedKidsHash.get(oldRowId);
 if(oldHash!=null){
 for(var z=0;z<oldHash.length;z++)
 oldHash[z].parent_id=newRowId;
 this.loadedKidsHash.put(newRowId,oldHash);
 this.loadedKidsHash.remove(oldRowId);
}
 var parentsHash = this.loadedKidsHash.get("hashOfParents")
 if(parentsHash!=null){
 if(parentsHash.get(oldRowId)!=null){
 parentsHash.put(newRowId,row);
 parentsHash.remove(oldRowId);
 this.loadedKidsHash.put("hashOfParents",parentsHash)
}
}
}

 this.rowsAr[oldRowId] = null;
 this.rowsAr[newRowId] = row;
}
 
 this.setColumnIds = function(ids){
 if(ids)
 this.columnIds = ids.split(",")
 if(this.hdr.rows.length>0){
 if(this.hdr.rows[0].cells.length>=this.columnIds.length){
 for(var i=0;i<this.columnIds.length;i++){
 this.hdr.rows[0].cells[i].column_id = this.columnIds[i];
}
}
}
}
 
 this.setColumnId = function(ind,id){this.hdr.rows[0].cells[ind].column_id = id;}
 
 this.getColIndexById = function(id){
 for(var i=0;i<this.hdr.rows[0].cells.length;i++){
 if(this.hdr.rows[0].cells[i].column_id==id)
 return i;
}
}
 
 this.getColumnId = function(cin){
 return this.hdr.rows[0].cells[cin].column_id
}

 
 this.getHeaderCol = function(cin){
 var z=this.hdr.rows[1]
 return z.cells[z._childIndexes?z._childIndexes[parseInt(cin)]:cin].childNodes[0].innerHTML;
}

 
 this.setRowTextBold = function(row_id){
 this.getRowById(row_id).style.fontWeight = "bold";
}
 
 this.setRowTextStyle = function(row_id,styleString){
 var r = this.getRowById(row_id)
 for(var i=0;i<r.childNodes.length;i++){
 var pfix="";


 if(dojo.render.html.ie)
 r.childNodes[i].style.cssText = pfix+"width:"+r.childNodes[i].style.width+";"+styleString;
 else
 r.childNodes[i].style.cssText = pfix+"width:"+r.childNodes[i].style.width+";"+styleString;
}

}
 
 this.setRowColor = function(row_id,color){
 var r = this.getRowById(row_id)
 for(var i=0;i<r.childNodes.length;i++)
 r.childNodes[i].bgColor=color;
}
 
 this.setCellTextStyle = function(row_id,ind,styleString){
 var r = this.getRowById(row_id)
 if(!r)return;
 if(ind<r.childNodes.length)
{
 var pfix="";

 if(dojo.render.html.ie)
 r.childNodes[ind].style.cssText = pfix+"width:"+r.childNodes[ind].style.width+";"+styleString;
 else
 r.childNodes[ind].style.cssText = pfix+"width:"+r.childNodes[ind].style.width+";"+styleString;
}

}

 
 this.setRowTextNormal = function(row_id){
 this.getRowById(row_id).style.fontWeight = "normal";
}
 
 this.isItemExists = function(row_id){
 if(this.getRowById(row_id)!=null)
 return true
 else
 return false
}

 
 this.getRowsNum = function(){
 if(this._dload)
 return this.limit;
 return this.rowsCol.length+this.rowsBuffer[0].length;
}
 
 this.getColumnCount = function(){
 return this.hdr.rows[0].cells.length;
}

 
 this.moveRowUp = function(row_id){
 var r = this.getRowById(row_id)
 var rInd = this.rowsCol._dhx_find(r)
 if(this.isTreeGrid()){
 if(this.rowsCol[rInd].parent_id!=this.rowsCol[rInd-1].parent_id)return;
 this.collapseKids(r);
}

 if((r.previousSibling)&&(rInd!=0)){
 r.parentNode.insertBefore(r,r.previousSibling)
 this.rowsCol._dhx_swapItems(rInd,rInd-1)
 this.setSizes();
}
}
 
 this.moveRowDown = function(row_id){
 var r = this.getRowById(row_id)
 var rInd = this.rowsCol._dhx_find(r)
 if(this.isTreeGrid())
 if(this.rowsCol[rInd].parent_id!=this.rowsCol[rInd+1].parent_id)return;

 if(r.nextSibling){
 this.rowsCol._dhx_swapItems(rInd,rInd+1)
 if(r.nextSibling.nextSibling)
 r.parentNode.insertBefore(r,r.nextSibling.nextSibling)
 else
 r.parentNode.appendChild(r)
 this.setSizes();
}
}
 
 this.cells = function(row_id,col){
 if(arguments.length==0)
 return this.cells4(this.cell);
 else
 var c = this.getRowById(row_id);
 var cell=(c._childIndexes?c.childNodes[c._childIndexes[col]]:c.childNodes[col]);
 return this.cells4(cell);
}
 
 this.cells2 = function(row_index,col){
 var c = this.rowsCol[parseInt(row_index)];
 var cell=(c._childIndexes?c.childNodes[c._childIndexes[col]]:c.childNodes[col]);
 return this.cells4(cell);
}

 
 this.cells3 = function(row,col){
 var cell=(row._childIndexes?row.childNodes[row._childIndexes[col]]:row.childNodes[col]);
 return this.cells4(cell);
}
 
 this.cells4 = function(cell){
 if(!cell._cellType)
 return eval("new eXcell_"+this.cellType[cell._cellIndex]+"(cell)");
 else
 return eval("new eXcell_"+cell._cellType+"(cell)");
}
 
 this.getCombo = function(col_ind){
 if(!this.combos[col_ind]){
 this.combos[col_ind] = new dhtmlXGridComboObject();
}
 return this.combos[col_ind];
}
 
 this.setUserData = function(row_id,name,value){
 try{
 if(row_id=="")
 row_id = "gridglobaluserdata";
 if(!this.UserData[row_id])
 this.UserData[row_id] = new Hashtable()
 this.UserData[row_id].put(name,value)
}catch(er){
 alert("UserData Error:"+er.description)
}
}
 
 this.getUserData = function(row_id,name){
 if(row_id=="")
 row_id = "gridglobaluserdata";
 var z=this.UserData[row_id];
 return(z?z.get(name):"");
}

 
 this.setEditable = function(fl){
 if(fl!='true' && fl!=1 && fl!=true)
 ifl = true;
 else
 ifl = false;
 for(var j=0;j<this.cellType.length;j++){
 if(this.cellType[j].indexOf('ra')==0 || this.cellType[j]=='ch'){
 for(var i=0;i<this.rowsCol.length;i++){
 var z=this.rowsCol[i].cells[j];
 if((z.childNodes.length>0)&&(z.firstChild.nodeType==1)){
 this.rowsCol[i].cells[j].firstChild.disabled = ifl;
}
}
}
}
 this.isEditable = !ifl;
}
 
 this.setSelectedRow = function(row_id,multiFL,show,call){
 if(!call)
 call = false;
 this.selectCell(this.getRowById(row_id),0,call,multiFL);
 if(arguments.length>2 && show==true){
 this.moveToVisible(this.getRowById(row_id).cells[0],true)
}
}
 
 this.clearSelection = function(){
 this.editStop()
 for(var i=0;i<this.selectedRows.length;i++){
 this.selectedRows[i].className=this.selectedRows[i].className.replace(/rowselected/g,"");
}

 
 this.selectedRows = new dhtmlxArray(0)
 this.row = null;
 if(this.cell!=null){
 this.cell.className = this.cell.className.replace(/cellselected/g,"");
 this.cell = null;
}
}
 
 this.copyRowContent = function(from_row_id,to_row_id){
 var frRow = this.getRowById(from_row_id)

 if(!this.isTreeGrid())
 for(i=0;i<frRow.cells.length;i++){
 this.cells(to_row_id,i).setValue(this.cells(from_row_id,i).getValue())
}
 else
 this._copyTreeGridRowContent(frRow,from_row_id,to_row_id);

 
 if(!isIE())
 this.getRowById(from_row_id).cells[0].height = frRow.cells[0].offsetHeight
}




 
 this.setHeaderCol = function(col,label){
 var z=this.hdr.rows[1];
 var col=(z._childIndexes?z._childIndexes[col]:col);
 if(!this.useImagesInHeader){
 var hdrHTML = "<div class='hdrcell'>"
 if(label.indexOf('img:[')!=-1){
 var imUrl = label.replace(/.*\[([^>]+)\].*/,"$1");
 label = label.substr(label.indexOf("]")+1,label.length)
 hdrHTML+="<img width='18px' height='18px' align='absmiddle' src='"+imUrl+"' hspace='2'>"
}
 hdrHTML+=label;
 hdrHTML+="</div>";
 z.cells[col].innerHTML = hdrHTML;

}else{
 z.cells[col].style.textAlign = "left";
 z.cells[col].innerHTML = "<img src='"+this.imgURL+""+label+"' onerror='this.src = \""+this.imgURL+"imageloaderror.gif\"'>";
 
 var a = new Image();
 a.src = this.imgURL+""+label.replace(/(\.[a-z]+)/,".desc$1");
 this.preloadImagesAr[this.preloadImagesAr.length] = a;
 var b = new Image();
 b.src = this.imgURL+""+label.replace(/(\.[a-z]+)/,".asc$1");
 this.preloadImagesAr[this.preloadImagesAr.length] = b;
}
}
 
 this.clearAll = function(header){
 this.limit=this._limitC=0;
 this.editStop();
 if(this._dLoadTimer)window.clearTimeout(this._dLoadTimer);
 if(this._dload){
 this.objBox.scrollTop=0;
 this.limit=this._limitC||0;
 this._initDrF=true;
}

 var len = this.rowsCol.length;
 
 if(this.loadedKidsHash!=null){
 this.loadedKidsHash.clear();
 this.loadedKidsHash.put("hashOfParents",new Hashtable());
}
 
 len = this.obj._rowslength();

 for(var i=len-1;i>=0;i--){
 var t_r=this.obj._rows(i);
 t_r.parentNode.removeChild(t_r);
}
 if(header){
 this.obj.rows[0].parentNode.removeChild(this.obj.rows[0]);
 for(var i=this.hdr.rows.length-1;i>=0;i--){
 var t_r=this.hdr.rows[i];
 t_r.parentNode.removeChild(t_r);
}
 this._aHead=this._aFoot=null;
}

 
 this.row = null;
 this.cell = null;


 this.rowsCol = new dhtmlxArray(0)
 this.rowsAr = new Array(0);
 this.rowsBuffer = new Array(new dhtmlxArray(0),new dhtmlxArray(0));
 this.UserData = new Array(0)

 if(this.pagingOn){
 this.changePage(1);
 
}

 if(!this._fake){
 if((this._hideShowColumn)&&(this.hdr.rows[0]))
 for(var i=0;i<this.hdr.rows[0].length;i++)
 this._hideShowColumn(i,"");
 this._hrrar=new Array();
}
 if(this._contextCallTimer)window.clearTimeout(this._contextCallTimer);


 if(this._sst)
 this.enableStableSorting(true);

 this.setSortImgState(false);
 this.setSizes();
 
}


 
 this.sortField = function(ind,repeatFl,r_el){
 if(this.getRowsNum()==0)
 return false;
 var el = this.hdr.rows[0].cells[ind];
 if(!el)return;
 if((this._dload)&&(this.onCLMS))return this.onCLMS(ind,this);
 if(el.tagName == "TH" &&(this.fldSort.length-1)>=el._cellIndex && this.fldSort[el._cellIndex]!='na'){
 if((((this.sortImg.src.indexOf("_desc.gif")==-1)&&(!repeatFl))||((this.sortImg.style.filter!="")&&(repeatFl)))&&(this.fldSorted==el)){
 var sortType = "desc";
 this.sortImg.src = this.imgURL+"sort_desc.gif";
}else{
 var sortType = "asc";
 this.sortImg.src = this.imgURL+"sort_asc.gif";
}
 if((this.onCLMS)&&(!this.onCLMS(ind,this,sortType)))return;

 
 if(this.useImagesInHeader){
 var cel=this.hdr.rows[1].cells[el._cellIndex].firstChild;
 if(this.fldSorted!=null){
 var celT=this.hdr.rows[1].cells[this.fldSorted._cellIndex].firstChild;
 celT.src = celT.src.replace(/\.[ascde]+\./,".");
}
 cel.src = cel.src.replace(/(\.[a-z]+)/,"."+sortType+"$1")
}
 
 this.sortRows(el._cellIndex,this.fldSort[el._cellIndex],sortType)
 this.fldSorted = el;this.r_fldSorted = r_el;
 var c=this.hdr.rows[1];
 var c=r_el.parentNode;
 var real_el=c._childIndexes?c._childIndexes[el._cellIndex]:el._cellIndex;
 this.setSortImgPos(false,false,false,r_el);
}
}



 
 this.enableHeaderImages = function(fl){
 this.useImagesInHeader = fl;
}

 
 this.setHeader = function(hdrStr,splitSign){
 var arLab = hdrStr.split(this.delim);
 var arWdth = new Array(0);
 var arTyp = new dhtmlxArray(0);
 var arAlg = new Array(0);
 var arVAlg = new Array(0);
 var arSrt = new Array(0);
 for(var i=0;i<arLab.length;i++){
 arWdth[arWdth.length] = Math.round(100/arLab.length);
 arTyp[arTyp.length] = "ed";
 arAlg[arAlg.length] = "left";
 arVAlg[arVAlg.length] = "";
 arSrt[arSrt.length] = "na";
}

 this.splitSign = splitSign||"#cspan";
 this.hdrLabels = arLab;
 this.cellWidth = arWdth;
 this.cellType = arTyp;
 this.cellAlign = arAlg;
 this.cellVAlign = arVAlg;
 this.fldSort = arSrt;
}


 
 this.getColType = function(cell_index){
 return this.cellType[cell_index];
}

 
 this.getColTypeById = function(col_id){
 return this.cellType[this.getColIndexById(col_id)];
}

 
 this.setColTypes = function(typeStr){
 this.cellType = dhtmlxArray(typeStr.split(this.delim));
 this._strangeParams=new Array();
 for(var i=0;i<this.cellType.length;i++)
 if((this.cellType[i].indexOf("[")!=-1))
{
 var z=this.cellType[i].split(/[\[\]]+/g);
 this.cellType[i]=z[0];
 this.defVal[i]=z[1];
 if(z[1].indexOf("=")==0){
 this.cellType[i]="math";
 this._strangeParams[i]=z[0];
}
}
}
 
 this.setColSorting = function(sortStr){
 this.fldSort = sortStr.split(this.delim)

}
 
 this.setColAlign = function(alStr){
 this.cellAlign = alStr.split(this.delim)
}
 
 this.setColVAlign = function(alStr){
 this.cellVAlign = alStr.split(this.delim)
}

 
 this.setMultiLine = function(fl){
 if(fl==true)
 this.multiLine = -1;
}
 
 this.setNoHeader = function(fl){
 if(fl==true)
 this.noHeader = true;
}
 
 this.showRow = function(rowID){
 if(this.pagingOn){
 if(this.rowsAr[rowID])
 this.changePage(Math.floor(this.getRowIndex(rowID)/this.rowsBufferOutSize)+1);
 else
 while((!this.rowsAr[rowID])&&(this.rowsBuffer[0].length>0 || !this.recordsNoMore))
 this.changePage(this.currentPage+1);
}

 this.moveToVisible(this.getRowById(rowID).cells[0],true)
}

 
 this.setStyle = function(ss_header,ss_grid,ss_selCell,ss_selRow){
 this.ssModifier = [ss_header,ss_grid,ss_selCell,ss_selCell,ss_selRow];
 var prefs=["#"+this.entBox.id+" table.hdr td","#"+this.entBox.id+" table.obj td","#"+this.entBox.id+" table.obj tr.rowselected td.cellselected","#"+this.entBox.id+" table.obj td.cellselected","#"+this.entBox.id+" table.obj tr.rowselected td"];

 for(var i=0;i<prefs.length;i++)
 if(this.ssModifier[i]){
 if(dojo.render.html.ie)
 this.styleSheet[0].addRule(prefs[i],this.ssModifier[i]);
 else
 this.styleSheet[0].insertRule(prefs[i]+"{"+this.ssModifier[i]+"}",0);
}
}
 
 this.setColumnColor = function(clr){
 this.columnColor = clr.split(this.delim)
}

 
 this.enableAlterCss = function(cssE,cssU){
 if(cssE||cssU)
 this.setOnGridReconstructedHandler(function(){
 this._fixAlterCss();
});


 this._cssEven = cssE;
 this._cssUnEven = cssU;
}

 
 this._fixAlterCss = function(ind){
 ind=ind||0;
 var j=ind;
 for(var i=ind;i<this.rowsCol.length;i++){
 if(!this.rowsCol[i])continue;
 if(this.rowsCol[i].style.display!="none"){
 if(this.rowsCol[i].className.indexOf("rowselected")!=-1){
 if(j%2==1)
 this.rowsCol[i].className=this._cssUnEven+" rowselected";
 else
 this.rowsCol[i].className=this._cssEven+" rowselected";
}
 else{
 if(j%2==1)
 this.rowsCol[i].className=this._cssUnEven;
 else
 this.rowsCol[i].className=this._cssEven;
}
 j++;
}
}
}


 
 this.doDynScroll = function(fl){
 if(!this.dynScroll || this.dynScroll=='false')
 return false;
 
 
 this.setDynScrollPageSize();
 

 var tmpAr = new Array(0)
 if(fl && fl=='up'){
 this.dynScrollPos = Math.max(this.dynScrollPos-this.dynScrollPageSize,0);
}else if(fl && fl=='dn' && this.dynScrollPos+this.dynScrollPageSize<this.rowsCol.length){
 if(this.dynScrollPos+this.dynScrollPageSize+this.rowsBufferOutSize>this.rowsCol.length){
 this.addRowsFromBuffer()
}
 this.dynScrollPos+=this.dynScrollPageSize
}
 var start = Math.max(this.dynScrollPos-this.dynScrollPageSize,0);
 for(var i = start;i<this.rowsCol.length;i++){
 if(i>=this.dynScrollPos && i<this.dynScrollPos+this.dynScrollPageSize){
 tmpAr[tmpAr.length] = this.rowsCol[i];
}
 this.rowsCol[i].parentNode.removeChild(this.rowsCol[i]);
}
 for(var i=0;i<tmpAr.length;i++){
 this.obj.childNodes[0].appendChild(tmpAr[i]);
 if(this.obj.offsetHeight>this.objBox.offsetHeight)
 this.dynScrollPos-=(this.dynScrollPageSize-i)
}
 this.setSizes()


}
 
 this.setDynScrollPageSize = function(){
 if(this.dynScroll && this.dynScroll!='false'){
 var rowsH = 0;
 try{
 var rowH = this.obj._rows(0).scrollHeight;
}catch(er){
 var rowH = 20
}
 for(var i=0;i<1000;i++){
 rowsH = i*rowH;
 if(this.objBox.offsetHeight<rowsH)
 break
}
 this.dynScrollPageSize = i+2;
 this.rowsBufferOutSize = this.dynScrollPageSize*4
}
}



 
this.dhx_attachEvent=function(original,catcher){
 if((!this[original])||(!this[original].dhx_addEvent)){
 var z=new this.dhx_eventCatcher(this);
 z.dhx_addEvent(this[original]);
 this[original]=z;
}
 this[original].dhx_addEvent(catcher);
}
 
this.dhx_eventCatcher=function(obj){
 var dhx_catch=new Array();
 var m_obj=obj;
 var z=function(){
 if(dhx_catch)
 var res=true;

 for(var i=0;i<dhx_catch.length;i++){
 var zr=dhx_catch[i].apply(m_obj,arguments);
 res=res?zr:res;}
 return res;
}
 z.dhx_addEvent=function(ev){
 if(typeof(ev)!="function")
 ev=eval(ev);
 if(ev)
 dhx_catch[dhx_catch.length]=ev;
}
 return z;
}

 
 
 
 this.setOnRowSelectHandler = function(func,anyClick){
 this.dhx_attachEvent("onRowSelect",func);
 this._chRRS=(!convertStringToBoolean(anyClick));
}


 
 this.setOnScrollHandler = function(func){
 this.dhx_attachEvent("_onSCRL",func);
}

 
 this.setOnEditCellHandler = function(func){
 this.dhx_attachEvent("onEditCell",func);
}
 
 this.setOnCheckHandler = function(func){
 this.dhx_attachEvent("onCheckbox",func);
}

 
 this.setOnEnterPressedHandler = function(func){
 this.dhx_attachEvent("onEnter",func);
}

 
 this.setOnBeforeRowDeletedHandler = function(func){
 this.dhx_attachEvent("onBeforeRowDeleted",func);
}
 
 this.setOnRowAddedHandler = function(func){
 this.dhx_attachEvent("onRowAdded",func);
}

 
 this.setOnGridReconstructedHandler = function(func){
 this.dhx_attachEvent("onGridReconstructed",func);
}
 




 
 this.getPosition = function(oNode,pNode){

 if(!pNode)
 var pNode = document.body

 var oCurrentNode=oNode;
 var iLeft=0;
 var iTop=0;
 while((oCurrentNode)&&(oCurrentNode!=pNode)){
 iLeft+=oCurrentNode.offsetLeft-oCurrentNode.scrollLeft;
 iTop+=oCurrentNode.offsetTop-oCurrentNode.scrollTop;
 oCurrentNode=oCurrentNode.offsetParent;
}
 if(pNode == document.body){
 if(dojo.render.html.ie){
 if(document.documentElement.scrollTop)
 iTop+=document.documentElement.scrollTop;
 if(document.documentElement.scrollLeft)
 iLeft+=document.documentElement.scrollLeft;
}
 else
 if(!dojo.render.html.moz){
 iLeft+=document.body.offsetLeft;
 iTop+=document.body.offsetTop;
}
}
 return new Array(iLeft,iTop);
}
 
 this.getFirstParentOfType = function(obj,tag){
 while(obj && obj.tagName && obj.tagName!=tag && obj.tagName!="BODY"){
 obj = obj.parentNode;
}
 return obj;
}

 
 
 this.setColumnCount = function(cnt){alert('setColumnCount method deprecated')}
 
 this.showContent = function(){alert('showContent method deprecated')}

 
 this.objBox.onscroll = new Function("","this.grid._doOnScroll()")
 if((!dojo.render.html.opera)||(_OperaRv>8.5))
{
 this.hdr.onmousemove = new Function("e","this.grid.changeCursorState(e||window.event)");
 this.hdr.onmousedown = new Function("e","this.grid.startColResize(e||window.event)");
}
 this.obj.onmousemove = this._drawTooltip;
 this.obj.onclick = new Function("e","this.grid._doClick(e||window.event);if(this.grid._sclE)this.grid.editCell(e||window.event);(e||event).cancelBubble=true;");
 this.entBox.onmousedown = new Function("e","return this.grid._doContClick(e||window.event);");
 this.obj.ondblclick = new Function("e","if(!this.grid.wasDblClicked(e||window.event)){return false};if(this.grid._dclE)this.grid.editCell(e||window.event);(e||event).cancelBubble=true;");
 this.hdr.onclick = this._onHeaderClick;
 this.hdr.ondblclick = this._onHeaderDblClick;

 
 if(!document.body._dhtmlxgrid_onkeydown){
 dhtmlxEvent(document,"keydown",new Function("e","if(globalActiveDHTMLGridObject)return globalActiveDHTMLGridObject.doKey(e||window.event);return true;"));
 document.body._dhtmlxgrid_onkeydown=true;
}

 dhtmlxEvent(document.body,"click",function(){if(self.editStop)self.editStop();return true;});

 
 
 this.entBox.onbeforeactivate = new Function("","this.grid.setActive();event.cancelBubble=true;");
 this.entBox.onbeforedeactivate = new Function("","this.grid.isActive=-1;event.cancelBubble=true;");
 
 this.doOnRowAdded = function(row){};
 return this;
}


 
 dhtmlXGridObject.prototype.isTreeGrid= function(){
 return(this.cellType._dhx_find("tree")!=-1);
}

 
 dhtmlXGridObject.prototype.addRow = function(new_id,text,ind){
 var r = this._addRow(new_id,text,ind);
 if(this.onRowAdded)
 this.onRowAdded(new_id);
 if(this.onRowCr)
 this.onRowCr(r.idd,r,null);
 if(this.pagingOn)
 this.changePage(this.currentPage)

 this.setSizes();
 r._added=true;
 return r;
}


 
 dhtmlXGridObject.prototype._prepareRow=function(new_id){
 var r=document.createElement("TR");
 r.idd = new_id;
 r.grid = this;

 for(var i=0;i<this.hdr.rows[0].cells.length;i++){
 var c = document.createElement("TD");
 
 if(this._enbCid)c.id="c_"+r.idd+"_"+i;
 
 c._cellIndex = i;
 if(this.dragAndDropOff)this.dragger.addDraggableItem(c,this);
 c.align = this.cellAlign[i];
 c.style.verticalAlign = this.cellVAlign[i];
 
 c.bgColor = this.columnColor[i] || "";




 r.appendChild(c);
}
 return r;
}
 
 dhtmlXGridObject.prototype._fillRow=function(r,text){
 if(!this._parsing_)this.editStop();

 this.math_off=true;
 this.math_req=false;

 if(typeof(text)!='object')
 text =(text||"").split(this.delim);
 for(var i=0;i<r.childNodes.length;i++){
 if((i<text.length)||(this.defVal[i])){
 var val = text[i]
 if((this.defVal[i])&&((val=="")||(val===window.undefined)))
 val = this.defVal[i];

 if((this._dload)&&(this.rowsAr[r.idd]))
 var aeditor = this.cells3(r,r.childNodes[i]._cellIndex);
 else
 aeditor = this.cells4(r.childNodes[i]);

 
 aeditor.setValue(val)
 aeditor = aeditor.destructor();
}else{
 var val = "&nbsp;";
 r.childNodes[i].innerHTML = val;
 r.childNodes[i]._clearCell=true;
}
}
 this.math_off=false;
 if((this.math_req)&&(!this._parsing_)){
 for(var i=0;i<this.hdr.rows[0].cells.length;i++)
 this._checkSCL(r.childNodes[i]);
 this.math_req=false;
}
 return r;
}

 
 dhtmlXGridObject.prototype._insertRowAt=function(r,ind,skip){
 if((ind<0)||((!ind)&&(parseInt(ind)!==0)))
 ind = this.rowsCol.length;
 else{
 if(ind>this.rowsCol.length)
 ind = this.rowsCol.length;
}

 if(!skip)
 if((ind==(this.obj.rows.length-1))||(!this.rowsCol[ind]))
 if(dojo.render.html.khtml)
 this.obj.appendChild(r);
 else{
 this.obj.firstChild.appendChild(r);
}
 else
{
 this.rowsCol[ind].parentNode.insertBefore(r,this.rowsCol[ind]);
}


 this.rowsAr[r.idd] = r;
 this.rowsCol._dhx_insertAt(ind,r);

 if(this._cssEven){
 if(ind%2==1)r.className+=" "+this._cssUnEven;
 else r.className+=" "+this._cssEven;

 if(ind!=(this.rowsCol.length-1))
 this._fixAlterCss(ind+1);
}

 
 this.doOnRowAdded(r);

 
 if((this.math_req)&&(!this._parsing_)){
 for(var i=0;i<this.hdr.rows[0].cells.length;i++)
 this._checkSCL(r.childNodes[i]);
 this.math_req=false;
}

 return r;
}

 
 dhtmlXGridObject.prototype._addRow = function(new_id,text,ind){
 var row = this._fillRow(this._prepareRow(new_id),text);
 if(ind>this.rowsCol.length && ind<(this.rowsCol.length+this.rowsBuffer[0].length)){
 var inBufInd = ind - this.rowsCol.length;
 this.rowsBuffer[0]._dhx_insertAt(inBufInd,new_id);
 this.rowsBuffer[1]._dhx_insertAt(inBufInd,row);
 return row;
}
 return this._insertRowAt(row,ind);
}

 
dhtmlXGridObject.prototype.setRowHidden=function(id,state){
 var f=convertStringToBoolean(state);
 
 
 
 var row= this.getRowById(id)
 if(!row)
 return;

 if(row.expand==="")
 this.collapseKids(row);

 if((state)&&(row.style.display!="none")){
 row.style.display="none";
 var z=this.selectedRows._dhx_find(row);
 if(z!=-1){
 row.className=row.className.replace("rowselected","");
 for(var i=0;i<row.childNodes.length;i++)
 row.childNodes[i].className=row.childNodes[i].className.replace(/cellselected/g,"");
 this.selectedRows._dhx_removeAt(z);
}
 if(this.onGridReconstructed)
 this.onGridReconstructed();
}

 if((!state)&&(row.style.display=="none")){
 row.style.display="";
 if(this.onGridReconstructed)this.onGridReconstructed();
}
 this.setSizes();
}


 
dhtmlXGridObject.prototype.enableRowsHover = function(mode,cssClass){
 this._hvrCss=cssClass;
 if(convertStringToBoolean(mode)){
 if(!this._elmnh){
 this.obj._honmousemove=this.obj.onmousemove;
 this.obj.onmousemove=this._setRowHover;
 if(dojo.render.html.ie)
 this.obj.onmouseleave=this._unsetRowHover;
 else
 this.obj.onmouseout=this._unsetRowHover;

 this._elmnh=true;
}
}else{
 if(this._elmnh){
 this.obj.onmousemove=this.obj._honmousemove;
 if(dojo.render.html.ie)
 this.obj.onmouseleave=null;
 else
 this.obj.onmouseout=null;

 this._elmnh=false;
}
}
};

 
dhtmlXGridObject.prototype.enableEditEvents = function(click,dblclick,f2Key){
 this._sclE = convertStringToBoolean(click);
 this._dclE = convertStringToBoolean(dblclick);
 this._f2kE = convertStringToBoolean(f2Key);
}


 
dhtmlXGridObject.prototype.enableLightMouseNavigation = function(mode){
 if(convertStringToBoolean(mode)){
 if(!this._elmn){
 this.entBox._onclick=this.entBox.onclick;
 this.entBox.onclick = function(){return true;};

 this.obj.onclick=function(e){
 var c = this.grid.getFirstParentOfType(e?e.target:event.srcElement,'TD');
 this.grid.editStop();
 this.grid.doClick(c);
 this.grid.editCell();
(e||event).cancelBubble=true;
}

 this.obj._onmousemove=this.obj.onmousemove;
 this.obj.onmousemove=this._autoMoveSelect;
 this._elmn=true;
}
}else{
 if(this._elmn){
 this.entBox.onclick = this.entBox._onclick;
 this.obj.onclick=function(){return true};
 this.obj.onmousemove=this.obj._onmousemove;
 this._elmn=false;
}
}
}


 
dhtmlXGridObject.prototype._unsetRowHover = function(e,c){
 if(c)that=this;else that=this.grid;

 if((that._lahRw)&&(that._lahRw!=c)){
 for(var i=0;i<that._lahRw.childNodes.length;i++)
 that._lahRw.childNodes[i].className=that._lahRw.childNodes[i].className.replace(that._hvrCss,"");
 that._lahRw=null;
}
}

 
dhtmlXGridObject.prototype._setRowHover = function(e){
 var c = this.grid.getFirstParentOfType(e?e.target:event.srcElement,'TD');
 if(c){
 this.grid._unsetRowHover(0,c);
 c=c.parentNode;
 for(var i=0;i<c.childNodes.length;i++)
 c.childNodes[i].className+=" "+this.grid._hvrCss;
 this.grid._lahRw=c;
}
 this._honmousemove(e);
}

 
dhtmlXGridObject.prototype._autoMoveSelect = function(e){
 
 if(!this.grid.editor)
{
 var c = this.grid.getFirstParentOfType(e?e.target:event.srcElement,'TD');
 if(c.parentNode.idd)
 this.grid.doClick(c,true,0);
}
 this._onmousemove(e);
}


 
dhtmlXGridObject.prototype.destructor=function(){
 var a;
 this.xmlLoader=this.xmlLoader.destructor();
 for(var i=0;i<this.rowsCol.length;i++)
 if(this.rowsCol[i])this.rowsCol[i].grid=null;
 for(i in this.rowsAr)
 if(this.rowsAr[i])this.rowsAr[i]=null;

 this.rowsCol=new dhtmlxArray();
 this.rowsAr=new Array();
 this.entBox.innerHTML="";
 this.entBox.onclick = function(){};
 this.entBox.onmousedown = function(){};
 this.entBox.onbeforeactivate = function(){};
 this.entBox.onbeforedeactivate = function(){};
 this.entBox.onbeforedeactivate = function(){};

 for(a in this){
 if((this[a])&&(this[a].m_obj))
 this[a].m_obj=null;
 this[a]=null;
}


 if(this==globalActiveDHTMLGridObject)
 globalActiveDHTMLGridObject=null;
 
 return null;
}





 
 dhtmlXGridObject.prototype.getSortingState=function(){
 var z=new Array();
 if(this.fldSorted){
 z[0]=this.fldSorted._cellIndex;
 z[1]=(this.sortImg.src.indexOf("sort_desc.gif")!=-1)?"DES":"ASC";
}
 return z;
};

 
 dhtmlXGridObject.prototype.enableAutoHeigth=function(mode,maxHeight,countFullHeight){
 this._ahgr=convertStringToBoolean(mode);
 this._ahgrF=convertStringToBoolean(countFullHeight);
 this._ahgrM=maxHeight||null;
 if(maxHeight=="auto")
{
 this._ahgrM=null;
 this._ahgrMA=true;
 
}
};

 
 dhtmlXGridObject.prototype.enableStableSorting=function(mode){
 this._sst=convertStringToBoolean(mode);
 this.rowsCol.stablesort=function(cmp){
 for(var i=0;i<this.length-1;i++)
 for(var j=i;j<this.length;j++)
 if(cmp(this[i],this[j])){
 var temp=this[j];
 this[j]=this[i];
 this[i]=temp;
}
}
};

 
 dhtmlXGridObject.prototype.enableKeyboardSupport=function(mode){
 this._htkebl=!convertStringToBoolean(mode);
};


 
 dhtmlXGridObject.prototype.enableContextMenu=function(menu){
 this._ctmndx=menu;
};
 
 dhtmlXGridObject.prototype.setOnBeforeContextMenu=function(func){
 this.dhx_attachEvent("onBCM",func);
};

 
dhtmlXGridObject.prototype.setOnRightClick=function(func){
 this.dhx_attachEvent("onRCL",func);
};



 
 dhtmlXGridObject.prototype.setScrollbarWidthCorrection=function(width){
 this._scrFix=parseInt(width);
};

 
 dhtmlXGridObject.prototype.enableTooltips=function(list){
 this._enbTts=list.split(",");
 for(var i=0;i<this._enbTts.length;i++)
 this._enbTts[i]=convertStringToBoolean(this._enbTts[i]);
};


 
 dhtmlXGridObject.prototype.enableResizing=function(list){
 this._drsclmn=list.split(",");
 for(var i=0;i<this._drsclmn.length;i++)
 this._drsclmn[i]=convertStringToBoolean(this._drsclmn[i]);
};

 
 dhtmlXGridObject.prototype.setColumnMinWidth=function(width,ind){
 if(arguments.length==2){
 if(!this._drsclmW)this._drsclmW=new Array();
 this._drsclmW[ind]=width;
}
 else
 this._drsclmW=width.split(",");
};


 
 
 dhtmlXGridObject.prototype.enableCellIds=function(mode){
 this._enbCid=convertStringToBoolean(mode);
};
 



 
 
 dhtmlXGridObject.prototype.lockRow=function(rowId,mode){
 var z=this.getRowById(rowId);
 if(z){
 z._locked=convertStringToBoolean(mode);
 if((this.cell)&&(this.cell.parentNode.idd==rowId))
 this.editStop();
}
};
 

 
 dhtmlXGridObject.prototype._getRowArray=function(row){
 var text=new Array();
 for(var ii=0;ii<row.childNodes.length;ii++)
 text[ii]=this.cells3(row,ii).getValue();
 return text;
}


 
 dhtmlXGridObject.prototype.parseXML = function(xml,startIndex){
 this._xml_ready=true;
 var pid=null;
 var zpid=null;
 if(!xml)
 try{
 var xmlDoc = eval(this.entBox.id+"_xml").XMLDocument;
}catch(er){
 var xmlDoc = this.loadXML(this.xmlFileUrl)
}
 else{
 if(typeof(xml)=="object"){
 var xmlDoc = xml;
}else{
 if(xml.indexOf(".")!=-1){
 if(this.xmlFileUrl=="")
 this.xmlFileUrl = xml
 var xmlDoc = this.loadXML(xml)
 return;
}else
 var xmlDoc = eval(xml).XMLDocument;
}
}





 var ar = new Array();
 var idAr = new Array();


 

 var tree=this.cellType._dhx_find("tree");
 var rowsCol = this.xmlLoader.doXPath("//rows/row",xmlDoc);
 if(rowsCol.length==0){
 this.recordsNoMore = true;
 var top=this.xmlLoader.doXPath("//rows",xmlDoc);
 var pid=(top[0].getAttribute("parent")||0);
 if((tree!=-1)&&(this.rowsAr[pid])){
 var tree_r=this.rowsAr[pid].childNodes[tree];
 tree_r.innerHTML=tree_r.innerHTML.replace(/\/(plus)\.gif/,"/blank.gif");
}
}
 else{
 pid=(rowsCol[0].parentNode.getAttribute("parent")||null);
 zpid=this.getRowById(pid);
 if(zpid)zpid._xml_await=false;
 else pid=null;
 startIndex=this.getRowIndex(pid)+1;
}

 
 var gudCol = this.xmlLoader.doXPath("//rows/userdata",xmlDoc);
 if(gudCol.length>0){
 this.UserData["gridglobaluserdata"] = new Hashtable();
 for(var j=0;j<gudCol.length;j++){
 this.UserData["gridglobaluserdata"].put(gudCol[j].getAttribute("name"),gudCol[j].firstChild?gudCol[j].firstChild.data:"");
}
}

 
 if(tree==-1)tree=this.cellType._dhx_find("3d");
 if(this._innerParse(rowsCol,startIndex,tree,pid)==-1)return;
 if(zpid)this.expandKids(zpid);

 if(this.dynScroll && this.dynScroll!='false'){
 this.doDynScroll()
}

 if(tree!=-1){
 var oCol = this.xmlLoader.doXPath("//row[@open]",xmlDoc);
 for(var i=0;i<oCol.length;i++)
 this.openItem(oCol[i].getAttribute("id"));
}

 this.setSizes();
 if(dojo.render.html.opera){
 this.obj.style.border=1;
 this.obj.style.border=0;
}
 this._startXMLLoading=false;



 if(this.onXLE)
 this.onXLE(this,rowsCol.length);
}
 
 dhtmlXGridObject.prototype._postRowProcessing=function(r,xml){
 var rId = xml.getAttribute("id");
 var xstyle = xml.getAttribute("style");

 
 var udCol = this.xmlLoader.doXPath("./userdata",xml);
 if(udCol.length>0){
 this.UserData[rId] = new Hashtable();
 for(var j=0;j<udCol.length;j++){
 this.UserData[rId].put(udCol[j].getAttribute("name"),udCol[j].firstChild?udCol[j].firstChild.data:"");
}
}

 
 var css1=xml.getAttribute("class");
 if(css1)r.className+=" "+css1;
 
 var css1=xml.getAttribute("bgColor");
 if(css1)
 for(var i=0;i<r.childNodes.length;i++)
 r.childNodes[i].bgColor=css1;
 
 
 if(xml.getAttribute("locked"))
{
 r._locked=true;
}
 


 
 if(xml.getAttribute("selected")==true){
 this.setSelectedRow(rId,this.selMultiRows,false,xml.getAttribute("call")==true)
}
 
 if(xml.getAttribute("expand")=="1"){
 r.expand = "";
}

 if(xstyle)this.setRowTextStyle(rId,xstyle);

 if(this.onRowCr)this.onRowCr(r.idd,r,xml);
}
 
 dhtmlXGridObject.prototype._fillRowFromXML=function(r,xml,tree,pId){
 var cellsCol = this.xmlLoader.doXPath("./cell",xml);
 var strAr = new Array(0);

 for(var j=0;j<cellsCol.length;j++){
 var cellVal=cellsCol[j];
 var exc=cellVal.getAttribute("type");

 if(cellVal.firstChild)
 cellVal=cellVal.firstChild.data;
 else cellVal="";
 if(j!=tree)
 strAr[strAr.length] = cellVal;
 else
 strAr[strAr.length] = [pId,cellVal,((xml.getAttribute("xmlkids")||r._xml)?"1":"0"),(cellsCol[j].getAttribute("image")||"folderOpen.gif")];

 if(exc)
 r.childNodes[j]._cellType=exc;

}
 if(this._c_order)strAr=this._swapColumns(strAr);
 for(var j=0;j<cellsCol.length;j++){
 css1=cellsCol[j].getAttribute("class");
 if(css1)r.childNodes[j].className+=" "+css1;
}
 this._fillRow(r,strAr);

 if((r.parentNode)&&(r.parentNode.tagName))
 this._postRowProcessing(r,xml);

 return r;
}


 
 dhtmlXGridObject.prototype._innerParse=function(rowsCol,startIndex,tree,pId,i){
 i=i||0;var imax=i+this._ads_count;
 var r=null;
 var rowsCol2;
 for(var i;i<rowsCol.length;i++){

 if((pId)||(i<this.rowsBufferOutSize || this.rowsBufferOutSize==0)){

 this._parsing_=true;
 var rId =(rowsCol[i].getAttribute("id")||(this.rowsCol.length+2));
 r=this._prepareRow(rId);

 if(tree!=-1){
 rowsCol2 = this.xmlLoader.doXPath("./row",rowsCol[i]);
 if((rowsCol2.length!=0)&&(this._slowParse))
 r._xml=rowsCol2;
}

 r=this._fillRowFromXML(r,rowsCol[i],tree,pId);

 if(startIndex){
 r = this._insertRowAt(r,startIndex);
 startIndex++;
}else{
 r = this._insertRowAt(r);
}

 this._postRowProcessing(r,rowsCol[i]);
 this._parsing_=false;
}
 else{
 var len = this.rowsBuffer[0].length
 this.rowsBuffer[1][len] = rowsCol[i];
 this.rowsBuffer[0][len] = rowsCol[i].getAttribute("id")
}

 if((tree!=-1)&&(rowsCol2.length!=0)&&(!this._slowParse))
 startIndex=this._innerParse(rowsCol2,startIndex,tree,rId);

}

 
 if(this.pagingOn && this.rowsBuffer[0].length>0){
 this.changePage(this.currentPage)
}

 if((r)&&(this._checkSCL))
 for(var i=0;i<this.hdr.rows[0].cells.length;i++)
 this._checkSCL(r.childNodes[i]);
 return startIndex;
}


 
 dhtmlXGridObject.prototype.getCheckedRows=function(col_ind){
 var d=new Array();
 for(var i=0;i<this.rowsCol.length;i++){
 if(this.cells3(this.rowsCol[i],col_ind).getValue()!="0")
 d[d.length]=this.rowsCol[i].idd;
}
 return d.join(",");
}
 
 dhtmlXGridObject.prototype._drawTooltip=function(e){
 var c = this.grid.getFirstParentOfType(e?e.target:event.srcElement,'TD');
 if((this.grid.editor)&&(this.grid.editor.cell==c))return true;

 var r = c.parentNode;
 if(r.idd==window.unknown)return true;
 if((this.grid._enbTts)&&(!this.grid._enbTts[c._cellIndex])){
(e?e.target:event.srcElement).title='';
 return true;}

 var ced = this.grid.cells(r.idd,c._cellIndex);

 if(ced)
(e?e.target:event.srcElement).title=ced.getTitle?ced.getTitle():(ced.getValue()||"").toString().replace(/<[^>]*>/gi,"");

 return true;
};

 
 dhtmlXGridObject.prototype.enableCellWidthCorrection=function(size){
 if(dojo.render.html.moz)this._wcorr=parseInt(size);
}


 
dhtmlXGridObject.prototype.getAllItemIds = function(separator){
 var ar = new Array(0)
 for(i=0;i<this.rowsCol.length;i++){
 ar[ar.length]=this.rowsCol[i].idd
}
 for(i=0;i<this.rowsBuffer[0].length;i++){
 ar[ar.length]=this.rowsBuffer[0][i]
}
 return ar.join(separator||",")
}

 
dhtmlXGridObject.prototype.deleteRow = function(row_id,node){
 
 if(!node)
 node = this.getRowById(row_id)
 if(!node)
 return;
 this.editStop();
 if(typeof(this.onBeforeRowDeleted)=="function" && this.onBeforeRowDeleted(row_id)==false)
 return false;

 if(node!=null){
 if(this.cellType._dhx_find("tree")!=-1)
 this._removeTrGrRow(node);
 if(node.parentNode){
 node.parentNode.removeChild(node);
}
 var ind=this.rowsCol._dhx_find(node);
 if(ind!=-1)
 this.rowsCol._dhx_removeAt(ind);
 else{
 ind = this.rowsBuffer[0]._dhx_find(row_id)
 if(ind>=0){
 this.rowsBuffer[0]._dhx_removeAt(ind)
 this.rowsBuffer[1]._dhx_removeAt(ind)
}

}
 node = null;
}

 for(var i=0;i<this.selectedRows.length;i++)
 if(this.selectedRows[i].idd==row_id)
 this.selectedRows._dhx_removeAt(i);

 this.rowsAr[row_id] = null;
 if(this.onGridReconstructed)
 this.onGridReconstructed();
 if(this.pagingOn){
 this.changePage();
}
 this.setSizes();
 return true;
}



 
dhtmlXGridObject.prototype.preventIECashing=function(mode){
 this.no_cashe = convertStringToBoolean(mode);
 this.xmlLoader.rSeed=this.no_cashe;
}


 
dhtmlXGridObject.prototype.enableColumnAutoSize = function(mode){
 this._eCAS=convertStringToBoolean(mode);
}
 
dhtmlXGridObject.prototype._onHeaderDblClick = function(e){
 var that=this.grid;
 var el = that.getFirstParentOfType(dojo.render.html.ie?event.srcElement:e.target,"TD");

 if(!that._eCAS)return false;
 that.adjustColumnSize(el._cellIndexS)
}

 
dhtmlXGridObject.prototype.adjustColumnSize = function(cInd){
 this._notresize=true;
 var m=0;
 this._setColumnSizeR(cInd,20);
 for(var j=1;j<this.hdr.rows.length;j++){
 var a=this.hdr.rows[j];
 a=a.childNodes[(a._childIndexes)?a._childIndexes[cInd]:cInd];

 if((a)&&((!a.colSpan)||(a.colSpan<2))){
 if((a.childNodes[0])&&(a.childNodes[0].className=="hdrcell"))a=a.childNodes[0];
 m+=a.scrollWidth;
}
}


 var l=this.obj._rowslength();
 for(var i=0;i<l;i++){
 if(dojo.render.html.moz||dojo.render.html.opera)
 var z=this.obj._rows(i).childNodes[cInd].innerHTML.replace(/<[^>]*>/g,"").length*7;
 else
 var z=this.obj._rows(i).childNodes[cInd].scrollWidth;
 if(z>m)m=z;
}
 m+=20;
 this._setColumnSizeR(cInd,m);
 this._notresize=false;
 this.setSizes();
}





 
dhtmlXGridObject.prototype.attachHeader = function(values,style,_type){
 if(typeof(values)=="string")values=values.split(this.delim);
 if(typeof(style)=="string")style=style.split(this.delim);
 _type=_type||"_aHead";
 if(this.hdr.rows.length){
 if(values)
 this._createHRow([values,style],this[(_type=="_aHead")?"hdr":"ftr"]);
 else if(this[_type])
 for(var i=0;i<this[_type].length;i++)
 this.attachHeader.apply(this,this[_type][i]);
}
 else{
 if(!this[_type])this[_type]=new Array();
 this[_type][this[_type].length]=[values,style,_type];
}
}

dhtmlXGridObject.prototype._createHRow = function(data,parent){
 if(!parent){
 
 this.entBox.style.position = "relative";
 var z=document.createElement("DIV");
 z.className="ftr";
 this.entBox.appendChild(z);
 var t=document.createElement("TABLE");
 t.cellPadding=t.cellSpacing=0;
 if(!dojo.render.html.ie){
 t.width="100%";
 t.style.paddingRight="20px";
}
 t.style.tableLayout = "fixed";

 z.appendChild(t);
 t.appendChild(document.createElement("TBODY"));
 this.ftr=parent=t;

 var hdrRow =t.insertRow(0);
 var thl=((this.hdrLabels.length<=1)?data[0].length:this.hdrLabels.length);
 for(var i=0;i<thl;i++){
 hdrRow.appendChild(document.createElement("TH"));
 hdrRow.childNodes[i]._cellIndex=i;
}

 if(dojo.render.html.ie)hdrRow.style.position="absolute";
 else hdrRow.style.height='auto';

}
 var st1=data[1];
 var z=document.createElement("TR");
 parent.rows[0].parentNode.appendChild(z);
 for(var i=0;i<data[0].length;i++){
 if(data[0][i]=="#cspan"){
 var pz=z.cells[z.cells.length-1];
 pz.colSpan=(pz.colSpan||1)+1;
 continue;
}
 if((data[0][i]=="#rspan")&&(parent.rows.length>1)){
 var pind=parent.rows.length-2;
 var found=false;
 var pz=null;
 while(!found){
 var pz=parent.rows[pind];
 for(var j=0;j<pz.cells.length;j++)
 if(pz.cells[j]._cellIndex==i){
 found=j+1;
 break;
}
 pind--;
}

 pz=pz.cells[found-1];
 pz.rowSpan=(pz.rowSpan||1)+1;
 continue;
 
}

 var w=document.createElement("TD");
 w._cellIndex=w._cellIndexS=i;
 if(this.forceDivInHeader)
 w.innerHTML="<div class='hdrcell'>"+data[0][i]+"</div>";
 else
 w.innerHTML=data[0][i];
 if(st1)w.style.cssText = st1[i];

 z.appendChild(w);
}
 var self=parent;
 if(dojo.render.html.khtml){
 if(parent._kTimer)window.clearTimeout(parent._kTimer);
 parent._kTimer=window.setTimeout(function(){
 parent.rows[1].style.display='none';
 window.setTimeout(function(){parent.rows[1].style.display='';},1);
},500);
}
}


//====Rex.Sun@10:20 2007-4-3 Add : dhtmlXGrid_srnd.js
/*
Copyright Scand LLC http://www.scbr.com
This version of Software is free for using in non-commercial applications. 
For commercial use please contact info@scbr.com to obtain license

*/
 
 dhtmlXGridObject.prototype.enableSmartRendering = function(mode,totalRows,bufferSize,renderSize){
 this._dload=convertStringToBoolean(mode)
 if(!this._dload){
 if(this.deleteRow_WSRD){
 this.deleteRow=this.deleteRow_WSRD;
 this._insertRowAt=this._insertRowAt_WSRD;
 this._initDrF=false;
}
 return;
}
 if(!this._srdh)this._srdh=20;

 if(!this.deleteRow_WSRD){
 this.deleteRow_WSRD=this.deleteRow;
 this.deleteRow=this.deleteRow_WSRDA;

 this._insertRowAt_WSRD=this._insertRowAt;
 this._insertRowAt=this._insertRowAt_WSRDA;
}


 this._dInc=12;
 this._dl_start=new Array();
 this._limitC=this.limit=totalRows;

 this.multiLine=false;
 this._dloadSize=Math.floor(parseInt(this.entBox.style.height)/this._srdh)+2;
 this.renderSize=renderSize;
 this.obj.className+=" row20px";

 if(this.hdr.childNodes[1])
 this._initD();
 else
 this._initDrF=true;

}

 
 dhtmlXGridObject.prototype.getStateOfView = function(){
 if(!this._srdh)this._srdh=20;
 return [
 Math.floor(this.objBox.scrollTop/this._srdh),
 Math.ceil(parseInt(this.objBox.offsetHeight)/this._srdh),
 this.limit
 ];
}
 

 dhtmlXGridObject.prototype._initD = function(){
 if((this.fldSort)&&(this.fldSort.length))
 for(var i=0;i<this.fldSort.length;i++)this.fldSort[i]="na";

 if(this.limit)
 this._fastAddRowSpacer(0,this.limit*this._srdh);


 this._initDrF=false;
}


 
 dhtmlXGridObject.prototype.enableDOMLimit = function(mode,limit){
 if(!convertStringToBoolean(mode))return;
 this._dom_limit=limit||1000;
}




 
 dhtmlXGridObject.prototype._addFromBufferSR=function(j){
 if((!this.rowsCol[j])||(this.rowsCol[j]._sRow))
 this._splitRowAt(j);
 else
 if((this.rowsBuffer[1][j])&&(this.rowsBuffer[1][j].tagName=="TR")){
 this.rowsCol[j].parentNode.insertBefore(this.rowsBuffer[1][j],this.rowsCol[j]);
 this.rowsCol[j].parentNode.removeChild(this.rowsCol[j]);
 this.rowsCol[j].grid=null;
 this.rowsCol[j]=this.rowsBuffer[1][j];
}


 if(this.rowsBuffer[1][j].tagName=="row"){
 if(this._cssEven){
 if(j%2==1)this.rowsCol[j].className=this._cssUnEven;
 else this.rowsCol[j].className=this._cssEven;
}
 this.changeRowId(this.rowsCol[j].idd,this.rowsBuffer[1][j].getAttribute("id"));
 this._fillRowFromXML(this.rowsCol[j],this.rowsBuffer[1][j],-1);
}
 else{
 this.rowsAr[this.rowsBuffer[1][j].idd]=this.rowsBuffer[1][j];
 this.rowsBuffer[1][j]._sRow=this.rowsBuffer[1][j]._rLoad=false;
}



 this.rowsCol[j]._rLoad=false;
 this.rowsBuffer[1][j]=null;
}

 
 dhtmlXGridObject.prototype._askRealRows=function(pos,afterCall){
 if((this.renderSize)&&(this.renderSize>this._dloadSize))
 var cdload=this.renderSize;
 else
 var cdload=this._dloadSize;
 if(!this.limit){
 this._dl_start[0]=[0,cdload];
 var loader = new dtmlXMLLoaderObject(this._askRealRows2,this);
 if(this._dloadStr)
 loader.loadXMLString(this._dloadStr);
 else
 loader.loadXML(this._dload+((this._dload.indexOf("?")!=-1)?"&":"?")+"posStart="+0+"&sn="+(new Date()).valueOf());
 
 return true;
}
 var gi=pos||Math.floor(this.objBox.scrollTop/this._srdh);
 if((this._dom_limit)&&(this.obj._rowslength()>this._dom_limit))
{

}
 
 if(gi>(this.limit-cdload))gi=this.limit-cdload;
 if(gi<0)gi=0;

 var size=gi+cdload;
 if(size>this.limit)size=this.limit;

 for(var j=gi;j<size;j++)
 if((!this.rowsCol[j])||(this.rowsCol[j]._rLoad)||(this.rowsCol[j]._sRow)){
 if(this.rowsBuffer[1][j])
{
 this._addFromBufferSR(j);
}
 else
{

{count=size-gi;start=gi;}
 this._dl_start[start]=[gi-start,size-gi];
 var loader = new dtmlXMLLoaderObject(this._askRealRows2,this);

 if(afterCall)loader.waitCall=afterCall;
 loader.loadXML(this._dload+((this._dload.indexOf("?")!=-1)?"&":"?")+"posStart="+start+"&count="+count+"&sn="+(new Date()).valueOf());
 if(this.onXLS)this.onXLS(this);
 return;
}
}
}


 dhtmlXGridObject.prototype._askRealRows2=function(obj,xml,c,d,e){
 var top=e.getXMLTopNode("rows");
 var inmd=obj._initDrF;

 if(inmd){

}

 var rows=e.doXPath("//rows/row",top);
 var z_t=top.getAttribute("total_count");
 if((z_t)&&(!obj._limitC)){
 obj._limitC=obj.limit=parseInt(z_t);
 
}


 if(inmd)obj._initD();



 var j=parseInt(top.getAttribute("pos"))||0;
 var llim=(obj._dl_start[j]||[0])[0];
 var tlim=llim+(obj._dl_start[j]||[0,rows.length])[1];



 for(var i=0;i<rows.length;i++){

{
 if((!obj.rowsCol[i+j])||(obj.rowsCol[i+j]._sRow))
 obj._splitRowAt(i+j);

 if(obj.rowsCol[i+j]._rLoad){
 
 if(obj._cssEven){
 if((j+i)%2==1)obj.rowsCol[i+j].className=obj._cssUnEven;
 else obj.rowsCol[i+j].className=obj._cssEven;
}
 obj.changeRowId(obj.rowsCol[i+j].idd,rows[i].getAttribute("id"));
 obj._fillRowFromXML(obj.rowsCol[i+j],rows[i],-1);
 obj.rowsCol[i+j]._rLoad=false;
}
}
}

 if(obj.onXLE)obj.onXLE(this,tlim-llim);
}
 
 dhtmlXGridObject.prototype._splitRowAt=function(ind){
 var id='temp_dLoad_'+this._dInc;
 this._dInc++;
 var z=this.rowsCol[ind];
 if(!z)
{
 
 var ind2=this._findSParent(ind);


 var delta=ind2[1]-(ind-ind2[0])*this._srdh;
 this._fixHeight(this.rowsCol[ind2[0]],delta);


 var z2=this._fastAddRow(id,ind,true,ind2[0])
 z2._sRow=true;

 this._fixHeight(z2,-1*((ind2[1]-(ind-ind2[0])*this._srdh)-this._srdh));
 return this._splitRowAt(ind);
}
 else
 if(z._sRow){
 
 if((this.rowsBuffer[1][ind])&&(this.rowsBuffer[1][ind].tagName=="TR"))
(this._fastAddRow(id,ind,true,null,this.rowsBuffer[1][ind]))._rLoad=false;
 else
(this._fastAddRow(id,ind,true))._rLoad=true;
 this.rowsCol[ind+1]=z;
 this._fixHeight(z,this._srdh);
 if(ind==0)this.setSizes();
}

}
 
 dhtmlXGridObject.prototype._findSParent=function(ind){
 for(var i=ind-1;i>=0;i--){
 if(this.rowsCol[i]){
 return [i,(parseInt(this.rowsCol[i].style.height))];
}
}
}
 
 dhtmlXGridObject.prototype._fixHeight=function(z,delta){
 var x=parseInt(z.style.height||this._srdh)-delta;
 if(x==this._srdh){z._sRow=false;z._rLoad=true;}

 z.style.height=x+"px";
 var n=z.childNodes.length;
 for(var i=0;i<n;i++)
 z.childNodes[i].style.height=x+"px";
}
 
 dhtmlXGridObject.prototype._fastAddRowSpacer=function(ind,height){
 var id='temp_dLoad_'+this._dInc;
 this._dInc++;

 var z=this._fastAddRow(id,ind);
 z.style.height=height+"px";
 var n=z.childNodes.length;
 for(var i=0;i<n;i++)
 z.childNodes[i].style.height=height+"px";

 z._sRow=true;
}


 
 dhtmlXGridObject.prototype._fastAddRow=function(id,ind,nonshift,ind2,z){
 var z=z||this._prepareRow(id);


 if(((ind2)||(ind2=="0"))&&(this.rowsCol[ind2].nextSibling))
 this.rowsCol[ind2].parentNode.insertBefore(z,this.rowsCol[ind2].nextSibling);
 else
{
 if((ind==this.limit)||(this.obj._rowslength()==0)||(!this.rowsCol[ind])){
 if(dojo.render.html.khtml)
 this.obj.appendChild(z);
 else{
 if(!this.obj.firstChild)
 this.obj.appendChild(document.createElement("TBODY"));
 this.obj.childNodes[0].appendChild(z);
}
}
 else
 this.rowsCol[ind2||ind].parentNode.insertBefore(z,this.rowsCol[ind]);
}


 this.rowsAr[id] = z;
 if(!nonshift)
 this.rowsCol._dhx_insertAt(ind,z);
 else
 this.rowsCol[ind]=z;

 return z;
};

 
dhtmlXGridObject.prototype.getAllItemIds = function(separator){
 var ar = new Array(0)
 var z=this.getRowsNum();
 for(i=0;i<z;i++)
 if((this.rowsCol[i])&&(!this.rowsCol[i]._sRow)&&(!this.rowsCol[i]._rLoad))
 ar[ar.length]=this.rowsCol[i].idd;
 else if(this.rowsBuffer[1][i])
 ar[ar.length]=this.rowsBuffer[0][i];

 return ar.join(separator||",")
}

 
dhtmlXGridObject.prototype._insertRowAt_WSRDA = function(r,ind,skip){
 if(ind<0)ind=this.rowsBuffer[0].length;
 if((arguments.length<2)||(ind===window.undefined))
 ind = this.rowsBuffer[0].length 
 else{
 if(ind>this.rowsBuffer[0].length)
 ind = this.rowsBuffer[0].length;
}

 var ind2=this.rowsBuffer[0][ind]||this.rowsCol[ind].idd;
 this.getRowById(ind2);


 if(!skip)
 if(ind==this.rowsBuffer[0].length){
 if(dojo.render.html.khtml)
 this.obj.appendChild(r);
 else{
 this.obj.firstChild.appendChild(r);
}
 this.rowsBuffer[0][ind]=r.idd;
 this.rowsBuffer[1][ind]=null;
 ind2=ind;
}
 else
{
 if(!this.rowsCol[ind])
 ind2=(this._findSParent(ind)[0]);
 else ind2=ind;
 this.rowsCol[ind2].parentNode.insertBefore(r,this.rowsCol[ind2]);
 this.rowsBuffer[0]._dhx_insertAt(ind,r.idd);
 this.rowsBuffer[1]._dhx_insertAt(ind,null);
}

 this.limit+=1;
 this.rowsAr[r.idd] = r;
 this.rowsCol._dhx_insertAt(ind2,r);

 if(this._cssEven){
 if(ind%2==1)r.className+=" "+this._cssUnEven;
 else r.className+=" "+this._cssEven;

 if(ind!=(this.rowsCol.length-1))
 this._fixAlterCss(ind+1);
}

 this.doOnRowAdded(r);
 if((this.math_req)&&(!this._parsing_)){
 for(var i=0;i<this.hdr.rows[0].cells.length;i++)
 this._checkSCL(r.childNodes[i]);
 this.math_req=false;
}
 return r;
}
 
dhtmlXGridObject.prototype.deleteRow_WSRDA = function(row_id,node){
 var ind=-1;
 var fixind=null;
 if(this.rowsAr[row_id]){
 ind=this.rowsCol._dhx_find(this.rowsAr[row_id]);
 if(this.deleteRow_WSRD(row_id,node)==false)return false;
}
 if(ind<0){
 var ind=this.rowsBuffer[0]._dhx_find(row_id);
 if(ind>-1)fixind=this.rowsCol[this._findSParent(ind)[0]];
}

 if(ind>-1)
{
 this.rowsBuffer[0]._dhx_delAt(ind);
 this.rowsBuffer[1]._dhx_delAt(ind);
 this.limit-=1;
 if(fixind)this._fixHeight(fixind,this._srdh);
}
 return true;
}


//====Rex.Sun@10:20 2007-4-3 Add : dhtmlXGridCell.js
/*
Copyright Scand LLC http://www.scbr.com
This version of Software is free for using in non-commercial applications. 
For commercial use please contact info@scbr.com to obtain license

*/ 

 
dhtmlXGridCellObject=function(obj){
 
 this.destructor=function(){
 this.cell.obj=null;
 this.cell=null;
 this.grid=null;
 this.base=null;
 return null;
}
 this.cell = obj;
 
 this.getValue = function(){
 if((this.cell.firstChild)&&(this.cell.firstChild.tagName=="TEXTAREA"))
 return this.cell.firstChild.value;
 else
 return this.cell.innerHTML._dhx_trim();
}

 
 this.getMathValue = function(){
 if(this.cell._val)
 return this.cell._val;
 else return this.getValue();
}
 
 this.getFont = function(){
 arOut = new Array(3);
 if(this.cell.style.fontFamily)
 arOut[0] = this.cell.style.fontFamily
 if(this.cell.style.fontWeight=='bold' || this.cell.parentNode.style.fontWeight=='bold')
 arOut[1] = 'bold';
 if(this.cell.style.fontStyle=='italic' || this.cell.parentNode.style.fontWeight=='italic')
 arOut[1]+= 'italic';
 if(this.cell.style.fontSize)
 arOut[2] = this.cell.style.fontSize
 else
 arOut[2] = "";
 return arOut.join("-")
}
 
 this.getTextColor = function(){
 if(this.cell.style.color)
 return this.cell.style.color
 else
 return "#000000";
}
 
 this.getBgColor = function(){
 if(this.cell.bgColor)
 return this.cell.bgColor
 else
 return "#FFFFFF";
}
 
 this.getHorAlign = function(){
 if(this.cell.style.textAlign)
 return this.cell.style.textAlign;
 else if(this.cell.align)
 return this.cell.align
 else
 return "left";
}
 
 this.getWidth = function(){
 return this.cell.scrollWidth;
}

 
 this.setFont = function(val){
 fntAr = val.split("-");
 this.cell.style.fontFamily = fntAr[0];
 this.cell.style.fontSize = fntAr[fntAr.length-1]
 if(fntAr.length==3){
 if(/bold/.test(fntAr[1]))
 this.cell.style.fontWeight = "bold";
 if(/italic/.test(fntAr[1]))
 this.cell.style.fontStyle = "italic";
 if(/underline/.test(fntAr[1]))
 this.cell.style.textDecoration = "underline";

}

}
 
 this.setTextColor = function(val){
 this.cell.style.color = val;
}
 
 this.setBgColor = function(val){
 if(val=="")
 val = null;
 this.cell.bgColor = val;
}
 
 this.setHorAlign = function(val){
 if(val.length==1){
 if(val=='c')
 this.cell.style.textAlign = 'center'
 else if(val=='l')
 this.cell.style.textAlign = 'left';
 else
 this.cell.style.textAlign = 'right';
}else
 this.cell.style.textAlign = val
}
 
 this.wasChanged = function(){
 if(this.cell.wasChanged)
 return true;
 else
 return false;
}
 
 this.isCheckbox = function(){
 var ch = this.cell.firstChild;
 if(ch && ch.tagName=='INPUT'){
 type = ch.type;
 if(type=='radio' || type=='checkbox')
 return true;
 else
 return false;
}else
 return false;
}
 
 this.isChecked = function(){
 if(this.isCheckbox()){
 return this.cell.firstChild.checked;
}
}
 
 this.isDisabled = function(){
 return this.cell._disabled;
}
 
 this.setChecked = function(fl){
 if(this.isCheckbox()){
 if(fl!='true' && fl!=1)
 fl = false;
 this.cell.firstChild.checked = fl;
}
}
 
 this.setDisabled = function(fl){
 if(fl!='true' && fl!=1)
 fl = false;
 if(this.isCheckbox()){
 this.cell.firstChild.disabled = fl;
 if(this.disabledF)this.disabledF(fl);
}
 this.cell._disabled = fl;
}
}

 
dhtmlXGridCellObject.prototype.setValue = function(val){
 if((typeof(val)!="number")&&(!val || val.toString()._dhx_trim()=="")){
 val="&nbsp;"
 this.cell._clearCell=true;
}
 this.setCValue(val);
}

dhtmlXGridCellObject.prototype.setCValue = function(val,val2){
 this.cell.innerHTML = val;

}
dhtmlXGridCellObject.prototype.setCTxtValue = function(val){
 this.cell.innerHTML="";
 this.cell.appendChild(document.createTextNode(val));

}

 
dhtmlXGridCellObject.prototype.setLabel = function(val){
 this.cell.innerHTML = val;
}

 
dhtmlXGridCellObject.prototype.getMath = function(){
 if(this._val)return this.val;
 else
 return this.getValue();
}

 
eXcell=function(){
 this.obj = null;
 
 this.val = null;
 
 this.changeState = function(){return false}
 
 this.edit = function(){this.val = this.getValue()}
 
 this.detach = function(){return false}
 
 this.getPosition = function(oNode){
 var oCurrentNode=oNode;
 var iLeft=0;
 var iTop=0;
 while(oCurrentNode.tagName!="BODY"){
 iLeft+=oCurrentNode.offsetLeft;
 iTop+=oCurrentNode.offsetTop;
 oCurrentNode=oCurrentNode.offsetParent;
}
 return new Array(iLeft,iTop);
}
}
eXcell.prototype = new dhtmlXGridCellObject;

 
eXcell_ed=function(cell){
 if(cell){
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
}
 this.edit = function(){
 this.cell.atag=((!this.grid.multiLine)&&(dojo.render.html.khtml||dojo.render.os.osx||dojo.render.html.moz))?"INPUT":"TEXTAREA";
 this.val = this.getValue();
 this.obj = document.createElement(this.cell.atag);
 this.obj.style.height =(this.cell.offsetHeight-(dojo.render.html.ie?6:4))+"px";
 this.obj.className="dhx_combo_edit";
 this.obj.wrap = "soft";
 this.obj.style.textAlign = this.cell.align;
 this.obj.onclick = function(e){(e||event).cancelBubble = true}
 this.obj.onmousedown = function(e){(e||event).cancelBubble = true}
 this.obj.value = this.val
 this.cell.innerHTML = "";
 this.cell.appendChild(this.obj);
 if(dojo.render.html.moz){
 this.obj.style.overflow="visible";
 if((this.grid.multiLine)&&(this.obj.offsetHeight>=18)&&(this.obj.offsetHeight<40)){
 this.obj.style.height="36px";
 this.obj.style.overflow="scroll";
}
}
 this.obj.onselectstart=function(e){if(!e)e=event;e.cancelBubble=true;return true;};
 this.obj.focus()
 this.obj.focus()
}
 this.getValue = function(){
 if((this.cell.firstChild)&&((this.cell.atag)&&(this.cell.firstChild.tagName==this.cell.atag)))
 return this.cell.firstChild.value;
 else
 return this.cell.innerHTML.toString()._dhx_trim();
}

 this.detach = function(){
 this.setValue(this.obj.value);
 return this.val!=this.getValue();
}

}
eXcell_ed.prototype = new eXcell;

 
eXcell_edtxt=function(cell){
 try{
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
}catch(er){}
 this.getValue = function(){
 if((this.cell.firstChild)&&((this.cell.atag)&&(this.cell.firstChild.tagName==this.cell.atag)))
 return this.cell.firstChild.value;
 else
 return(dojo.render.html.ie?this.cell.innerText:this.cell.textContent);
}
 this.setValue = function(val){
 if(!val || val.toString()._dhx_trim()=="")
 val=" ";
 this.setCTxtValue(val);
}
}
eXcell_edtxt.prototype = new eXcell_ed;



 
eXcell_ch=function(cell){
 if(cell){
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
 this.cell.obj = this;
}

 this.disabledF=function(fl){
 if((fl==true)||(fl==1))
 this.cell.innerHTML=this.cell.innerHTML.replace("item_chk0.","item_chk0_dis.").replace("item_chk1.","item_chk1_dis.");
 else
 this.cell.innerHTML=this.cell.innerHTML.replace("item_chk0_dis.","item_chk0.").replace("item_chk1_dis.","item_chk1.");
}

 this.changeState = function(){
 
 if((!this.grid.isEditable)||(this.cell.parentNode._locked)||(this.isDisabled()))return;
 if(this.grid.onEditCell(0,this.cell.parentNode.idd,this.cell._cellIndex)){
 this.val = this.getValue()
 if(this.val=="1")
 this.setValue("0")
 else
 this.setValue("1")

 this.cell.wasChanged=true;
 
 this.grid.onEditCell(1,this.cell.parentNode.idd,this.cell._cellIndex)
 this.grid.onCheckbox(this.cell.parentNode.idd,this.cell._cellIndex,(this.val!='1'))
}else{
 this.editor=null;
}
}
 this.getValue = function(){
 try{
 return this.cell.chstate.toString();
}catch(er){
 return null;
}
}

 this.isCheckbox = function(){
 return true;
}
 this.isChecked = function(){
 if(this.getValue()=="1")
 return true;
 else
 return false;
}
 this.setChecked = function(fl){
 this.setValue(fl.toString())
}
 this.detach = function(){
 return this.val!=this.getValue();
}
}
eXcell_ch.prototype = new eXcell;
eXcell_ch.prototype.setValue = function(val){
 this.cell.style.verticalAlign = "middle";
 
 if(val){
 val=val.toString()._dhx_trim();
 if((val=="false")||(val=="0"))val="";
}
 if(val){
 val = "1";
 this.cell.chstate = "1";
}else{
 val = "0";
 this.cell.chstate = "0"
}
 var obj = this;
 this.setCValue("<img src='"+this.grid.imgURL+"item_chk"+val+".gif' onclick='new eXcell_ch(this.parentNode).changeState();(arguments[0]||event).cancelBubble=true;'>",this.cell.chstate);
}

 
eXcell_ra=function(cell){
 this.base = eXcell_ch;
 this.base(cell)
 this.grid = cell.parentNode.grid;

 this.disabledF=function(fl){
 if((fl==true)||(fl==1))
 this.cell.innerHTML=this.cell.innerHTML.replace("radio_chk0.","radio_chk0_dis.").replace("radio_chk1.","radio_chk1_dis.");
 else
 this.cell.innerHTML=this.cell.innerHTML.replace("radio_chk0_dis.","radio_chk0.").replace("radio_chk1_dis.","radio_chk1.");
}

 this.changeState = function(){
 if((!this.grid.isEditable)||(this.cell.parentNode._locked))return;
 if(this.grid.onEditCell(0,this.cell.parentNode.idd,this.cell._cellIndex)!=false){
 this.val = this.getValue()
 if(this.val=="1")
 this.setValue("0")
 else
 this.setValue("1")
 this.cell.wasChanged=true;
 
 this.grid.onEditCell(1,this.cell.parentNode.idd,this.cell._cellIndex)
 if(typeof(this.grid.onCheckbox)=='function')
 this.grid.onCheckbox(this.cell.parentNode.idd,this.cell._cellIndex,(this.val!='1'))
 for(var i=0;i<this.grid.getRowsNum();i++){
 if(this.grid.cells2(i,this.cell._cellIndex).isChecked()&& this.grid.cells2(i,this.cell._cellIndex).cell!=this.cell)
{
 this.grid.cells2(i,this.cell._cellIndex).setValue("0")
 this.grid.onEditCell(1,this.grid.rowsCol[i].idd,this.cell._cellIndex);
}
}
}else{
 this.editor=null;
}
}

}
eXcell_ra.prototype = new eXcell_ch;
eXcell_ra.prototype.setValue = function(val){
 this.cell.style.verticalAlign = "middle";
 if(val){
 val=val.toString()._dhx_trim();
 if((val=="false")||(val=="0"))val="";
}
 if(val){
 val = "1";
 this.cell.chstate = "1";
}else{
 val = "0";
 this.cell.chstate = "0"
}
 var obj = this;
 this.setCValue("<img src='"+this.grid.imgURL+"radio_chk"+val+".gif' onclick='this.parentNode.obj.changeState()'>",this.cell.chstate);
}
 
eXcell_txt=function(cell){
 try{
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
}catch(er){}
 this.edit = function(){
 this.val = this.getValue()
 this.obj = document.createElement("TEXTAREA");
 this.obj.className="dhx_textarea";

 this.obj.onclick = function(e){(e||event).cancelBubble = true}
 var arPos = this.grid.getPosition(this.cell);
 if(!this.cell._clearCell)
 this.obj.value = this.cell.innerHTML.replace(/<br[^>]*>/gi,"\n");

 this.obj.style.display = "";
 this.obj.style.textAlign = this.cell.align;
 if(dojo.render.html.moz){
 var z_ff=document.createElement("DIV");
 z_ff.appendChild(this.obj);
 z_ff.style.overflow="auto";
 z_ff.className="dhx_textarea";
 this.obj.style.margin="0px 0px 0px 0px";
 this.obj.style.border="0px";
 this.obj=z_ff;
}
 document.body.appendChild(this.obj);
 this.obj.onkeydown=function(e){
 var ev=(e||event);
 if(ev.keyCode==9){
 globalActiveDHTMLGridObject.entBox.focus();
 globalActiveDHTMLGridObject.doKey({keyCode:ev.keyCode,shiftKey:ev.shiftKey,srcElement:"0"});
 return false;
}
}

 this.obj.style.left = arPos[0]+"px";
 this.obj.style.top = arPos[1]+this.cell.offsetHeight+"px";
 if(this.cell.scrollWidth<200)
 var pw=200;
 else
 var pw=this.cell.scrollWidth;
 this.obj.style.width = pw+(dojo.render.html.moz?18:16)+"px"
 if(dojo.render.html.moz){
 this.obj.firstChild.style.width = parseInt(this.obj.style.width)+"px";
 this.obj.firstChild.style.height = this.obj.offsetHeight-3+"px";
}

 this.obj.focus();
 if(dojo.render.html.moz)this.obj.firstChild.focus();
 else this.obj.focus()

}
 this.detach = function(){
 var a_val="";
 if(dojo.render.html.moz)a_val=this.obj.firstChild.value;
 else a_val=this.obj.value;
 if(a_val==""){
 this.cell._clearCell=true;
}
 else this.cell._clearCell=false;
 this.setValue(a_val);
 
 document.body.removeChild(this.obj);

 return this.val!=this.getValue();
}
 this.getValue = function(){
 if(this.cell.firstChild){
 if(this.cell.firstChild.tagName=="TEXTAREA")
 return this.obj.firstChild.value;
 else
 if(this.cell.firstChild.tagName=="DIV")
 return this.obj.firstChild.firstChild.value;
}
 if((!dojo.render.html.ie)&&(!this.grid.multiLine))
 return this.cell.innerHTML;
 else
 return this.cell.innerHTML.replace(/<br[^>]*>/gi,"\n")._dhx_trim();
}
}
eXcell_txt.prototype = new eXcell;

eXcell_txt.prototype.setValue = function(val){
 if(!val || val.toString()._dhx_trim()==""){
 val="&nbsp;"
 this.cell._clearCell=true;
}
 if((!dojo.render.html.ie)&&(!this.grid.multiLine))
 this.setCValue(val,val);
 else
 this.setCValue(val.replace(/\n/g,"<br/>"),val);
}


 
eXcell_co=function(cell){
 if(cell){
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
 this.combo = this.grid.getCombo(this.cell._cellIndex);
 this.editable = true
}
 this.shiftNext=function(){

 var z=this.list.options[this.list.selectedIndex+1];
 if(z)z.selected=true;
 this.obj.value=this.list.value;

 return true;
}
 this.shiftPrev=function(){

 var z=this.list.options[this.list.selectedIndex-1];
 if(z)z.selected=true;

 this.obj.value=this.list.value;

 return true;
}

 this.edit = function(){
 this.val = this.getValue();
 this.text = this.cell.innerHTML._dhx_trim();
 var arPos = this.grid.getPosition(this.cell)

 this.obj = document.createElement("TEXTAREA");
 this.obj.className="dhx_combo_edit";
 this.obj.style.height=(this.cell.offsetHeight-4)+"px";

 this.obj.wrap = "soft";
 this.obj.style.textAlign = this.cell.align;
 this.obj.onclick = function(e){(e||event).cancelBubble = true}
 this.obj.value = this.text

 this.list = document.createElement("SELECT");
 this.list.editor_obj = this;
 this.list.className='dhx_combo_select';
 this.list.style.width=this.cell.offsetWidth+"px";
 this.list.style.left = arPos[0]+"px";
 this.list.style.top = arPos[1]+this.cell.offsetHeight+"px";
 this.list.onclick = function(e){
 var ev = e||window.event;
 var cell = ev.target||ev.srcElement

 if(cell.tagName=="OPTION")cell=cell.parentNode;
 cell.editor_obj.setValue(cell.value);
 cell.editor_obj.editable=false;
 cell.editor_obj.grid.editStop();
}
 var comboKeys = this.combo.getKeys();
 var fl=false
 var selOptId=0;
 for(var i=0;i<comboKeys.length;i++){
 var val = this.combo.get(comboKeys[i])
 this.list.options[this.list.options.length]=new Option(val,comboKeys[i]);
 if(comboKeys[i]==this.val){
 selOptId=this.list.options.length-1;
 fl=true;
}
}

 if(fl==false){
 this.list.options[this.list.options.length]=new Option(this.text,this.val===null?"":this.val);
 selOptId=this.list.options.length-1;
}
 document.body.appendChild(this.list)
 this.list.size="6";
 this.cstate=1;
 if(this.editable){
 this.cell.innerHTML = "";
}
 else{
 this.obj.style.width="1px";
 this.obj.style.height="1px";
}
 this.cell.appendChild(this.obj);
 this.list.options[selOptId].selected=true;
 
 if((!dojo.render.html.moz)||(this.editable)){
 this.obj.focus();
 this.obj.focus();
}
 if(!this.editable)
 this.obj.style.visibility="hidden";
}

 this.getValue = function(){
 return((this.cell.combo_value==window.undefined)?"":this.cell.combo_value);
}
 this.getText = function(){
 return this.cell.innerHTML;
}
 this.detach = function(){
 if(this.val!=this.getValue()){
 this.cell.wasChanged = true;
}

 if(this.list.parentNode!=null){
 if(this.editable)
 if(this.obj.value._dhx_trim()!=this.text){
 this.setValue(this.obj.value)
}else{
 this.setValue(this.val)
}
 else
 this.setValue(this.list.value)
}
 if(this.list.parentNode)
 this.list.parentNode.removeChild(this.list);
 if(this.obj.parentNode)
 this.obj.parentNode.removeChild(this.obj);

 return this.val!=this.getValue();
}
}
eXcell_co.prototype = new eXcell;
eXcell_co.prototype.setValue = function(val){
 if((val||"").toString()._dhx_trim()=="")
 val=null

 if(val!==null)
 this.setCValue(this.grid.getCombo(this.cell._cellIndex).get(val)|| val,val);
 else
 this.setCValue("&nbsp;",val);

 this.cell.combo_value = val;
}
 
eXcell_coro=function(cell){
 this.base = eXcell_co;
 this.base(cell)
 this.editable = false;
}
eXcell_coro.prototype = new eXcell_co;

 
eXcell_cp=function(cell){
 try{
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
}catch(er){}
 this.edit = function(){
 this.val = this.getValue()
 this.obj = document.createElement("SPAN");
 this.obj.style.border = "1px solid black";
 this.obj.style.position = "absolute";
 var arPos = this.grid.getPosition(this.cell);
 this.colorPanel(4,this.obj)
 document.body.appendChild(this.obj);
 this.obj.style.left = arPos[0]+"px";
 this.obj.style.top = arPos[1]+this.cell.offsetHeight+"px";
}
 this.toolDNum = function(value){
 if(value.length==1)
 value = '0'+value;
 return value;
}
 this.colorPanel = function(index,parent){
 var tbl = document.createElement("TABLE");
 parent.appendChild(tbl)
 tbl.cellSpacing = 0;
 tbl.editor_obj = this;
 tbl.style.cursor = "default";
 tbl.style.cursor = "table-layout:fixed";
 tbl.onclick = function(e){
 var ev = e||window.event
 var cell = ev.target||ev.srcElement;
 var ed = cell.parentNode.parentNode.parentNode.editor_obj
 ed.setValue(cell.style.backgroundColor)
 ed.grid.editStop();
}
 var cnt = 256/index;
 for(var j=0;j<=(256/cnt);j++){
 var r = tbl.insertRow(j);
 for(var i=0;i<=(256/cnt);i++){
 for(var n=0;n<=(256/cnt);n++){
 R = new Number(cnt*j)-(j==0?0:1)
 G = new Number(cnt*i)-(i==0?0:1)
 B = new Number(cnt*n)-(n==0?0:1)
 var rgb = this.toolDNum(R.toString(16))+""+this.toolDNum(G.toString(16))+""+this.toolDNum(B.toString(16));
 var c = r.insertCell(i);
 c.width = "10px";
 c.innerHTML = "&nbsp;";
 c.title = rgb.toUpperCase()
 c.style.backgroundColor = "#"+rgb
 if(this.val!=null && "#"+rgb.toUpperCase()==this.val.toUpperCase()){
 c.style.border = "2px solid white"
}
}
}
}
}
 this.getValue = function(){
 return this.cell.firstChild.style?this.cell.firstChild.style.backgroundColor:"";
}
 this.getRed = function(){
 return Number(parseInt(this.getValue().substr(1,2),16))
}
 this.getGreen = function(){
 return Number(parseInt(this.getValue().substr(3,2),16))
}
 this.getBlue = function(){
 return Number(parseInt(this.getValue().substr(5,2),16))
}
 this.detach = function(){
 if(this.obj.offsetParent!=null)
 document.body.removeChild(this.obj);
 
 return this.val!=this.getValue();
}
}
eXcell_cp.prototype = new eXcell;
eXcell_cp.prototype.setValue = function(val){
 this.setCValue("<div style='width:100%;height:"+(this.cell.offsetHeight-2)+";background-color:"+(val||"")+";border:0px;'>&nbsp;</div>",val);
}


 
 
eXcell_img=function(cell){
 try{
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
}catch(er){}
 this.getValue = function(){
 if(this.cell.firstChild.tagName=="IMG")
 return this.cell.firstChild.src+(this.cell.titFl!=null?"^"+this.cell.tit:"");
 else if(this.cell.firstChild.tagName=="A"){
 var out = this.cell.firstChild.firstChild.src+(this.cell.titFl!=null?"^"+this.cell.tit:"");
 out+="^"+this.cell.lnk;
 if(this.cell.trg)
 out+="^"+this.cell.trg
 return out;
}
}
 this.getTitle = function(){
 return this.cell.tit
}
}
eXcell_img.prototype = new eXcell;
eXcell_img.prototype.setValue = function(val){
 var title = val;
 if(val.indexOf("^")!=-1){
 var ar = val.split("^");
 val = ar[0]
 title = ar[1];
 
 if(ar.length>2){
 this.cell.lnk = ar[2]
 if(ar[3])
 this.cell.trg = ar[3]
}
 this.cell.titFl = "1";
}
 this.setCValue("<img src='"+(val||"")._dhx_trim()+"' border='0'>",val);
 if(this.cell.lnk){
 this.cell.innerHTML = "<a href='"+this.cell.lnk+"' target='"+this.cell.trg+"'>"+this.cell.innerHTML+"</a>"
}
 this.cell.tit = title;
}

 
eXcell_price=function(cell){
 this.base = eXcell_ed;
 this.base(cell)
 this.getValue = function(){
 if(this.cell.childNodes.length>1)
 return this.cell.childNodes[1].innerHTML.toString()._dhx_trim()
 else
 return "0";
}
}
eXcell_price.prototype = new eXcell_ed;
eXcell_price.prototype.setValue = function(val){
 if(isNaN(Number(val))){
 if(!(val||"")||(val||"")._dhx_trim()!="")
 val = 0;
 val = this.val || 0;
}
 if(val>0){
 var color = "green";
 this.setCValue("<span>$</span><span style='padding-right:2px;color:"+color+";'>"+val+"</span>",val);
}else{
 this.setCValue("<div align='center' style='color:red;'>&nbsp;</div>",0);
}

}

 
eXcell_dyn=function(cell){
 this.base = eXcell_ed;
 this.base(cell)
 this.getValue = function(){
 return this.cell.firstChild.childNodes[1].innerHTML.toString()._dhx_trim()
}

}

eXcell_dyn.prototype = new eXcell_ed;
eXcell_dyn.prototype.setValue = function(val){
 if(!val || isNaN(Number(val))){
 val = 0;
}
 if(val>0){
 var color = "green";
 var img = "dyn_up.gif";
}else if(val==0){
 var color = "black";
 var img = "dyn_.gif";
}else{
 var color = "red";
 var img = "dyn_down.gif";
}
 this.setCValue("<div style='position:relative;padding-right:2px;width:100%;'><img src='"+this.grid.imgURL+""+img+"' height='15' style='position:absolute;top:0px;left:0px;'><span style='width:100%;color:"+color+";'>"+val+"</span></div>",val);
}


 
eXcell_ro=function(cell){
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
 this.edit = function(){}
 this.isDisabled = function(){return true;}
}
eXcell_ro.prototype = new eXcell;


 
dhtmlXGridComboObject=function(){
 this.keys = new dhtmlxArray();
 this.values = new dhtmlxArray();
 
 this.put = function(key,value){
 for(var i=0;i<this.keys.length;i++){
 if(this.keys[i]==key){
 this.values[i]=value;
 return true;
}
}
 this.values[this.values.length] = value;
 this.keys[this.keys.length] = key;
}
 
 this.get = function(key){
 for(var i=0;i<this.keys.length;i++){
 if(this.keys[i]==key){
 return this.values[i];
}
}
 return null;
}
 
 this.clear = function(){
 
 this.keys = new dhtmlxArray();
 this.values = new dhtmlxArray();
}
 
 this.remove = function(key){
 for(var i=0;i<this.keys.length;i++){
 if(this.keys[i]==key){
 this.keys._dhx_removeAt(i);
 this.values._dhx_removeAt(i);
 return true;
}
}
}
 
 this.size = function(){
 var j=0;
 for(var i=0;i<this.keys.length;i++){
 if(this.keys[i]!=null)
 j++;
}
 return j;
}
 
 this.getKeys = function(){
 var keyAr = new Array(0);
 for(var i=0;i<this.keys.length;i++){
 if(this.keys[i]!=null)
 keyAr[keyAr.length] = this.keys[i];
}
 return keyAr;
}

 
 this.save = function(){
 this._save=new Array();
 for(var i=0;i<this.keys.length;i++)
 this._save[i]=[this.keys[i],this.values[i]];
}


 
 this.restore = function(){
 if(this._save){
 this.keys[i]=new Array();
 this.values[i]=new Array();
 for(var i=0;i<this._save.length;i++){
 this.keys[i]=this._save[i][0];
 this.values[i]=this._save[i][1];
}
}
}
 return this;
}
Hashtable=function(){
 this.keys = new dhtmlxArray();
 this.values = new dhtmlxArray();
 return this;
}
Hashtable.prototype = new dhtmlXGridComboObject;


//====Rex.Sun@10:20 2007-4-3 Add : dhtmlXGrid_start.js
/*
Copyright Scand LLC http://www.scbr.com
This version of Software is free for using in non-commercial applications. 
For commercial use please contact info@scbr.com to obtain license

*/dhtmlXGridFromTable=function(obj){
 if(typeof(obj)!='object')
 obj = document.getElementById(obj);

 var w=document.createElement("DIV");
 w.setAttribute("width",obj.getAttribute("gridWidth")||(obj.offsetWidth+"px"));
 w.setAttribute("height",obj.getAttribute("gridHeight")||(obj.offsetHeight+"px"));

 var mr=obj;
 var drag=obj.getAttribute("dragAndDrop");

 mr.parentNode.insertBefore(w,mr);
 var f=mr.getAttribute("name")||("name_"+(new Date()).valueOf());

 var windowf=new dhtmlXGridObject(w);
 windowf.setImagePath(mr.getAttribute("imgpath")||"");

 var hrow=mr.rows[0];
 var za="";
 var zb="";
 var zc="";
 var zd="";
 var ze="";

 for(var i=0;i<hrow.cells.length;i++){
 za+=(za?",":"")+hrow.cells[i].innerHTML;
 zb+=(zb?",":"")+(parseInt(hrow.cells[i].getAttribute("width")||hrow.cells[i].offsetWidth));
 zc+=(zc?",":"")+(hrow.cells[i].getAttribute("align")||"left");
 zd+=(zd?",":"")+(hrow.cells[i].getAttribute("type")||"ed");
 ze+=(ze?",":"")+(hrow.cells[i].getAttribute("sort")||"str");
}

 windowf.setHeader(za);
 windowf.setInitWidths(zb)
 windowf.setColAlign(zc)
 windowf.setColTypes(zd);
 windowf.setColSorting(ze);
 if(obj.getAttribute("gridHeight")=="auto")
 windowf.enableAutoHeigth(true);

 if(obj.getAttribute("multiline"))windowf.enableMultiline(true);

 var lmn=mr.getAttribute("lightnavigation");
 if(lmn)windowf.enableLightMouseNavigation(lmn);

 var evr=mr.getAttribute("evenrow");
 var uevr=mr.getAttribute("unevenrow");

 if(evr||uevr)windowf.enableAlterCss(evr,uevr);
 if(drag)windowf.enableDragAndDrop(true);

 windowf.init();

 
 var n_l=mr.rows.length;
 for(var j=1;j<n_l;j++){
 var r=mr.rows[1];
 r.idd=r.id;
 if((!r.idd)||(windowf.rowsAr[r.idd]))
 r.idd=obj.id+"_"+j;
 windowf.rowsCol[windowf.rowsCol.length]=r;
 windowf.rowsAr[r.idd]=r;
 r.grid=windowf;

 if(evr)
 if((j%2)==1)
 r.className=evr;
 else
 r.className=uevr;


 windowf.obj.rows[0].parentNode.appendChild(r);
 for(var x=0;x<r.cells.length;x++)
 r.cells[x]._cellIndex=x;
 if(dojo.render.html.moz)
 for(var i=r.childNodes.length-1;i>=0;i--)
 if(r.childNodes[i].nodeType!=1)
 r.removeChild(r.childNodes[i]);

 if(drag)
 for(var i=r.childNodes.length-1;i>=0;i--)
 windowf.dragger.addDraggableItem(r.childNodes[i],windowf);
}

 mr.parentNode.removeChild(mr);

 if(obj.getAttribute("forceCellTypes"))
 for(var i=0;i<windowf.cellType.length;i++)
 if((windowf.cellType[i]=="ra")||(windowf.cellType[i]=="ch")||(windowf.cellType[i]=="img"))
 for(var j=0;j<windowf.rowsCol.length;j++)
 windowf.cells2(j,i).setValue(windowf.rowsCol[j].cells[i].innerHTML);

 windowf.setSizes();
 window[f]=windowf;
 return windowf;

}

dhx_init_grids=function(){
 var z=document.getElementsByTagName("table");
 for(var a=0;a<z.length;a++)
 if(z[a].className=="dhtmlxGrid"){
 dhtmlXGridFromTable(z[a]);
 
}
}

if(window.addEventListener)window.addEventListener("load",dhx_init_grids,false);
else if(window.attachEvent)window.attachEvent("onload",dhx_init_grids);


//====Rex.Sun@10:20 2007-4-3 Add : dhtmlXGrid_drag.js
/*
Copyright Scand LLC http://www.scbr.com
This version of Software is free for using in non-commercial applications. 
For commercial use please contact info@scbr.com to obtain license

*/ 

 
 dhtmlXGridObject.prototype.enableDragAndDrop=function(mode){
 if(mode=="temporary_disabled"){
 this.dADTempOff=false;
 mode=true;}
 else
 this.dADTempOff=true;

 this.dragAndDropOff=convertStringToBoolean(mode);
};

 
dhtmlXGridObject.prototype.setDragBehavior=function(mode){
 this.dadmodec=this.dadmodefix=0;
 switch(mode){
 case "child": this.dadmode=0;this._sbmod=false;break;
 case "sibling": this.dadmode=1;this._sbmod=false;break;
 case "sibling-next": this.dadmode=1;this._sbmod=true;break;
 case "complex": this.dadmode=2;this._sbmod=false;break;
 case "complex-next": this.dadmode=2;this._sbmod=true;break;
}};


 
dhtmlXGridObject.prototype.enableDragOrder=function(mode){
 this._dndorder=convertStringToBoolean(mode);
};

 
dhtmlXGridObject.prototype._createDragNode=function(htmlObject,e){
 this.editStop();

 if(!this.dADTempOff)return null;
 htmlObject.parentObject=new Object();
 htmlObject.parentObject.treeNod=this;

 var z=new Array();

 z[this.selMultiRows?z.length:0]=htmlObject.parentNode.idd;

 var self=this;
 if(z.length && this._dndorder)
 z.sort(function(a,b){return(self.rowsAr[a].rowIndex>self.rowsAr[b].rowIndex?1:-1);});

 var el = this.getFirstParentOfType(dojo.render.html.ie?e.srcElement:e.target,"TD");
 if(el)this._dndExtra=el._cellIndex;
 this._dragged=new Array();
 for(var i=0;i<z.length;i++)
 if(this.rowsAr[z[i]]){
 this._dragged[this._dragged.length]=this.rowsAr[z[i]];
 this.rowsAr[z[i]].treeNod=this;
}

 htmlObject.parentObject.parentNode=htmlObject.parentNode;

 var dragSpan=document.createElement('div');
 dragSpan.innerHTML=this.rowToDragElement(htmlObject.parentNode.idd);
 dragSpan.style.position="absolute";
 dragSpan.className="dragSpanDiv";
 return dragSpan;
}



 
dhtmlXGridObject.prototype._createSdrgc=function(){
 this._sdrgc=document.createElement("DIV");
 this._sdrgc.innerHTML="&nbsp;";
 this._sdrgc.className="gridDragLine";
 this.objBox.appendChild(this._sdrgc);
}











 
dragContext=function(a,b,c,d,e,f,j,h,k,l){
 this.source=a||"grid";
 this.target=b||"grid";
 this.mode=c||"move";
 this.dropmode=d||"child";
 this.sid=e||0;
 this.tid=f||window.unknown;
 this.sobj=j||null;
 this.tobj=h||null;
 this.sExtra=k||null;
 this.tExtra=l||null;
 return this;
}
 
dragContext.prototype.valid=function(){
 if(this.sobj!=this.tobj)return true;
 if(this.sid==this.tid)return false;
 if(this.target=="treeGrid"){
 var z=this.tid
 while(z = this.tobj.getParentId(z)){
 if(this.sid==z)return false;
}
}
 return true;
}
 
dragContext.prototype.close=function(){
 this.sobj=null;
 this.tobj=null;
}
 
dragContext.prototype.copy=function(){
 return new dragContext(this.source,this.target,this.mode,this.dropmode,this.sid,this.tid,this.sobj,this.tobj,this.sExtra,this.tExtra);
}
 
dragContext.prototype.set=function(a,b){
 this[a]=b;
 return this;
}
 
dragContext.prototype.uid=function(a,b){
 this.nid=this.sid;
 while(this.tobj.rowsAr[this.nid])
 this.nid=this.nid+((new Date()).valueOf());

 return this;
}
 
dragContext.prototype.data=function(){
 if(this.sobj==this.tobj)
 return this.sobj._getRowArray(this.sobj.rowsAr[this.sid]);
 if(this.source=="tree")
 return this.tobj.treeToGridElement(this.sobj,this.sid,this.tid);
 else
 return this.tobj.gridToGrid(this.sid,this.sobj,this.tobj);
}
 
dragContext.prototype.pid=function(){
 if(this.tid==window.unknown)return window.unknown;
 if(this.target=="treeGrid")
 if(this.dropmode=="child")
 return this.tid;
 else{
 var z=this.tobj.rowsAr[this.tid];
 if((this.alfa)&&(this.tobj._sbmod)&&(z.nextSibling)){
 if(z.nextSibling.parent_id==this.tid)
 return this.tid;
 if(z.nextSibling.parent_id!=z.parent_id)
 return z.nextSibling.parent_id;
}
 return z.parent_id;
}
}
 
dragContext.prototype.ind=function(){
 if(this.tid==window.unknown)return 0;
 if(this.target=="treeGrid"){
 if(this.dropmode=="child")
 this.tobj.openItem(this.tid);
 else
 this.tobj.openItem(this.tobj.getParentId(this.tid));
}
 var ind=this.tobj.rowsCol._dhx_find(this.tobj.rowsAr[this.tid]);
 if((this.alfa)&&(this.tobj._sbmod)&&(this.dropmode=="sibling")){
 var z=this.tobj.rowsAr[this.tid];
 if((z.nextSibling)&&(z.nextSibling.parent_id==this.tid))
 return ind+1;
}

 return(ind+((this.target=="treeGrid")?this.tobj._countBranchLength(ind):1));
}
 
dragContext.prototype.img=function(){
 if(this.target!="grid")
 return this.sobj.getItemImage(this.sid);
 else return null;
}

 
dragContext.prototype.slist=function(){
 var res=new Array();
 for(var i=0;i<this.sid.length;i++)
 res[res.length]=this.sid[i][(this.source=="tree")?"id":"idd"];

 return res.join(",");
}


 
dhtmlXGridObject.prototype._drag=function(sourceHtmlObject,dhtmlObject,targetHtmlObject,lastLanding){

 var z=(this.lastLanding)
 
 if(this._autoOpenTimer)window.clearTimeout(this._autoOpenTimer);

 
 var r1=targetHtmlObject.parentNode;
 var r2=sourceHtmlObject.parentObject;
 
 if(!r1.grid){r1.grid=this;this.dadmodefix=0;}

 var c=new dragContext(0,0,0,(r1.grid.dadmodec?"sibling":"child"));


 if(r2 && r2.childNodes)
 c.set("source","tree").set("sobj",r2.treeNod).set("sid",c.sobj._dragged);
 else{
 if(r2.treeNod.isTreeGrid())c.set("source","treeGrid");
 c.set("sobj",r2.treeNod).set("sid",c.sobj._dragged);
}


 if(r1.grid.isTreeGrid())
 c.set("target","treeGrid");
 else
 c.set("dropmode","sibling");
 c.set("tobj",r1.grid).set("tid",r1.idd);



 var el = this.getFirstParentOfType(lastLanding,"TD")
 if(el)c.set("tExtra",el._cellIndex);
 if(el)c.set("sExtra",c.sobj._dndExtra);

 if(c.sobj.dpcpy)c.set("mode","copy");
 c.tobj._clearMove();

 c.tobj.dragContext=c;
 if((c.tobj.dragFunc)&&(!c.tobj.dragFunc(c.slist(),c.tid,c.sobj,c.tobj,c.sExtra,c.tExtra)))return;

 
 var result=new Array();
 if(typeof(c.sid)=="object"){
 var nc=c.copy();
 for(var i=0;i<c.sid.length;i++){
 if(!nc.set("alfa",(!i)).set("sid",c.sid[i][(c.source=="tree"?"id":"idd")]).valid())continue;
 nc.tobj._dragRoutine(nc);
 result[result.length]=nc.nid;
 nc.set("dropmode","sibling").set("tid",nc.nid);
}
 nc.close();
}
 else
 c.tobj._dragRoutine(c);

 
 if(c.tobj.dropFunc)
 c.tobj.dropFunc(c.slist(),c.tid,result.join(","),c.sobj,c.tobj,c.sExtra,c.tExtra);

 c.tobj.dragContext=null;
 c.close();
}


 
dhtmlXGridObject.prototype._dragRoutine=function(c){
 if((c.sobj==c.tobj)&&(c.source=="grid")&&(c.mode=="move")){
 
 var fr=c.sobj.rowsAr[c.sid];
 c.sobj.rowsCol._dhx_removeAt(c.sobj.rowsCol._dhx_find(fr));
 c.sobj._insertRowAt(fr,c.ind());
 c.nid=c.sid;
 return;
}

 c.uid().tobj.addRow(c.nid,c.data(),c.ind(),c.pid(),c.img());

 if(c.source=="tree"){
 var sn=c.sobj._globalIdStorageFind(c.sid);
 if(sn.childsCount){
 var nc=c.copy().set("tid",c.nid).set("dropmode",c.target=="grid"?"sibling":"child");
 for(var j=0;j<sn.childsCount;j++){
 c.tobj._dragRoutine(nc.set("sid",sn.childNodes[j].id));
 if(c.mode=="move")j--;
}
 nc.close();
}
}
 else{
 c.tobj._copyUserData(c);
 if((c.source=="treeGrid")){
 var snc=c.sobj.loadedKidsHash.get(c.sid);
 if((snc)&&(snc.length)){
 var nc=c.copy().set("tid",c.nid);
 if(c.target=="grid")
 nc.set("dropmode","sibling");
 else{
 nc.tobj.openItem(c.tid);
 nc.set("dropmode","child");
}
 for(var j=0;j<snc.length;j++){
 c.tobj._dragRoutine(nc.set("sid",snc[j].idd));
 if(c.mode=="move")j--;
}
 nc.close();
}
}
}

 if(c.mode=="move"){
 c.sobj[(c.source=="tree")?"deleteItem":"deleteRow"](c.sid);
 if((c.sobj==c.tobj)&&(!c.tobj.rowsAr[c.sid])){
 c.tobj.changeRowId(c.nid,c.sid);
 c.nid=c.sid;
}
}
}


 
dhtmlXGridObject.prototype.gridToGrid = function(rowId,sgrid,tgrid){
 var z=new Array();
 for(var i=0;i<sgrid.hdr.rows[0].cells.length;i++)
 z[i]=sgrid.cells(rowId,i).getValue();
 return z;
}

 
dhtmlXGridObject.prototype.checkParentLine=function(node,id){
 if((!id)||(!node))return false;
 if(node.idd==id)return true;
 else return this.checkParentLine(this.getRowById(node.parent_id),id);
}

 
dhtmlXGridObject.prototype._dragIn=function(htmlObject,shtmlObject,x,y){
 if(!this.dADTempOff)return 0;
 var tree=this.isTreeGrid();

 if(htmlObject.parentNode==shtmlObject.parentNode)
 return 0;

 
 if((tree)&&((this.checkParentLine(htmlObject.parentNode,shtmlObject.parentNode.idd))))
 return 0;
 var obj=shtmlObject.parentNode.idd?shtmlObject.parentNode:shtmlObject.parentObject;
 if((this.dragInFunc)&&(!this.dragInFunc(obj.idd||obj.id,htmlObject.parentNode.idd,obj.grid||obj.treeNod,htmlObject.parentNode.grid)))
 return 0;

 this._setMove(htmlObject,x,y);

 if((tree)&&(htmlObject.parentNode.expand!="")){
 this._autoOpenTimer=window.setTimeout(new callerFunction(this._autoOpenItem,this),1000);
 this._autoOpenId=htmlObject.parentNode.idd;
}
 else
 if(this._autoOpenTimer)window.clearTimeout(this._autoOpenTimer);

 return htmlObject;
}
 
dhtmlXGridObject.prototype._autoOpenItem=function(e,gridObject){
 gridObject.openItem(gridObject._autoOpenId);
}

 
dhtmlXGridObject.prototype._dragOut=function(htmlObject){
 this._clearMove();
 if(this._autoOpenTimer)window.clearTimeout(this._autoOpenTimer);
}
 
dhtmlXGridObject.prototype._setMove=function(htmlObject,x,y){
 var a1=getAbsoluteTop(htmlObject);
 var a2=getAbsoluteTop(this.objBox);

 if(this.dadmode==2)
{

 var z=y-a1+this.objBox.scrollTop+(document.body.scrollTop||document.documentElement.scrollTop)-2-htmlObject.offsetHeight/2;
 if((Math.abs(z)-htmlObject.offsetHeight/6)>0)
{
 this.dadmodec=1;
 
 if(z<0)this.dadmodefix=-1;else this.dadmodefix=1;
}
 else this.dadmodec=0;
}
 else
 this.dadmodec=this.dadmode;


 
 if((a1-a2-parseInt(this.objBox.scrollTop))>(parseInt(this.objBox.offsetHeight)-50))
 this.objBox.scrollTop=parseInt(this.objBox.scrollTop)+20;
 
 if((a1-a2)<(parseInt(this.objBox.scrollTop)+30))
 this.objBox.scrollTop=parseInt(this.objBox.scrollTop)-20;

 if(this.dadmodec){
 if(!this._sdrgc)this._createSdrgc();
 this._sdrgc.style.display="block";
 this._sdrgc.style.top=a1-a2+((this.dadmodefix>=0)?htmlObject.offsetHeight:0)+"px";
}
 else{
 this._llSelD=htmlObject;
 
 if(htmlObject.parentNode.tagName=="TR")
 for(var i=0;i<htmlObject.parentNode.childNodes.length;i++)
{
 var z= htmlObject.parentNode.childNodes[i];
 z._bgCol=z.style.backgroundColor;
 z.style.backgroundColor="#FFCCCC";
}
}
}
 
dhtmlXGridObject.prototype._clearMove=function(){
 if(this._sdrgc)this._sdrgc.style.display="none";
 if((this._llSelD)&&(this._llSelD.parentNode.tagName=="TR"))
 for(var i=0;i<this._llSelD.parentNode.childNodes.length;i++)
 this._llSelD.parentNode.childNodes[i].style.backgroundColor=this._llSelD._bgCol;

 this._llSelD=null;
}


 
dhtmlXGridObject.prototype.rowToDragElement=function(gridRowId){
 var out=this.cells(gridRowId,0).getValue();
 return out;
}








 
dhtmlXGridObject.prototype._copyUserData = function(c){
 var z1 = c.sobj.UserData[c.sid];
 var z2 = new Hashtable();
 if(z1){
 z2.keys = z2.keys.concat(z1.keys);
 z2.values = z2.values.concat(z1.values);
}

 c.tobj.UserData[c.tid]=z2;
}



 
dhtmlXGridObject.prototype.moveRow=function(rowId,mode,targetId,targetGrid){
 switch(mode){
 case "row_sibling":
 this.moveRowTo(rowId,targetId,"move","sibling",this,targetGrid);
 break;
 case "up":
 this.moveRowUp(rowId);
 break;
 case "down":
 this.moveRowDown(rowId);
 break;
}
}



 
dhtmlXGridObject.prototype.setDragHandler=function(func){if(typeof(func)=="function")this.dragFunc=func;else this.dragFunc=eval(func);}

//====Rex.Sun@10:20 2007-4-3 Add : dhtmlXTreeGrid.js
/*
Copyright Scand LLC http://www.scbr.com
To use this component please contact info@scbr.com to obtain license

*/ 

 
dhtmlXGridObject.prototype.doExpand=function(obj){
 this.editStop();
 var row = obj.parentNode.parentNode.parentNode;
 var tbl = this.obj;
 var disp = "";
 if(obj.src.indexOf("plus")!=-1){
 this.expandKids(row,true)
}else{
 if(!row._closeable)
 this.collapseKids(row)
}
}




 
dhtmlXGridObject.prototype.collapseKids=function(curRow,kidsAr,start){
 if(curRow.expand!="")return;
 if((this._spnFH)&&(!this._spnFH(curRow.idd,1)))return;

 if(!start)
 start = curRow.rowIndex;

 if(!kidsAr){
 kidsAr = new dhtmlxArray(0)
 curRow.expand="none"
 treeCell = curRow.childNodes[this.cellType._dhx_find("tree")]
 treeCell.innerHTML = treeCell.innerHTML.replace(/\/minus\.gif/,"/plus.gif").replace(/folderopen\.gif/gi,"folderclosed.gif");;
}
 for(var i=start;i<this.obj._rowslength();i++){
 var row = this.obj._rows(i);
 if(row.parent_id==curRow.idd){
 if(row.expand=="")
 var add_fl = true
 else
 var add_fl = false
 if((this._fake)&&(!this._realfake))
 this._fake._collapseFake(row,i);
 kidsAr[kidsAr.length] = row.parentNode.removeChild(row);
 this.rowsCol._dhx_removeAt(i)
 if(add_fl)
 this.collapseKids(row,null,i)
 i--;
}
}

 if(this._ahgr)this.setSizes();



 this.loadedKidsHash.put(curRow.idd,kidsAr)
 if(arguments.length==1){
 if(this._epnFH)this._epnFH(curRow.idd,-1);
}

 return kidsAr;
}


 
 dhtmlXGridObject.prototype._changeParent=function(r2,r1){
 if(!r1){
 r2.parent_id=0;
 return;
}
 if(r2.parent_id==r1.idd){
 var a=this.loadedKidsHash.get(r1.idd);
 var z=a._dhx_find(r2);
 a._dhx_removeAt(z);
 if(this._dhkPos){
 if(this._dhkPos>z)this._dhkPos--;
 a._dhx_insertAt(this._dhkPos,r2);
}
 this.loadedKidsHash.put(r1.idd,a);
 
 return;
}
 var a=this.loadedKidsHash.get(r2.parent_id);
 var b=this.loadedKidsHash.get(r1.idd);
 if(!b)b=new dhtmlxArray();
 if(a){
 a._dhx_removeAt(a._dhx_find(r2));
 this.loadedKidsHash.put(r2.parent_id,a);
}
 if(this._dhkPos){
 b._dhx_insertAt(this._dhkPos,r2);
}
 else
 b._dhx_insertAt(0,r2);
 this.loadedKidsHash.put(r1.idd,b);

 r2.parent_id=r1.idd;
}


 
dhtmlXGridObject.prototype.expandKids=function(curRow){
 if((curRow.has_kids==0)&&(!curRow._xml_await))return;
 if(curRow.expand=="")return;
 if(!curRow._loading)
 if((this._spnFH)&&(!this._spnFH(curRow.idd,-1)))return;


 var start = this.getRowIndex(curRow.idd)+1;
 var kidsAr = this.loadedKidsHash.get(curRow.idd);

 if(kidsAr!=null){
 curRow._loading=false;
 curRow.expand = "";
 if(this._fake)
 this._fake._expandCorrect(curRow);
 treeCell = curRow.childNodes[this.cellType._dhx_find("tree")];
 treeCell.innerHTML = treeCell.innerHTML.replace(/\/(plus|blank)\.gif/,"/minus.gif").replace(/folderclosed\.gif/gi,"folderopen.gif");;

 for(var i=0;i<kidsAr.length;i++){
 
 this._insertRowAt(kidsAr[i],start);
 
 start++;
}
 if(this._cssEven)
 this._fixAlterCss(start-i<kidsAr.length);

 if(this.fldSorted!=null){
 this.sortTreeRows(this._ls_col,this._ls_type,this._ls_order);
 if(this._epnFH)this._epnFH(curRow.idd,1);
}
}else{
 if(curRow._xml_await){
 if((this._slowParse)&&(curRow._xml)){
 this._reParse(curRow);
 return this.expandKids(curRow);
}
 if(this.kidsXmlFile.indexOf("?")!=-1)
 var s = "&";
 else
 var s = "?";
 curRow._loading=true;
 this.loadXML(this.kidsXmlFile+""+s+"id="+curRow.idd);
}
}
 if((this._ahgr)&&(!this._startXMLLoading))this.setSizes();
 if(!curRow._loading)
 if(this._epnFH)this._epnFH(curRow.idd,1);
}

dhtmlXGridObject.prototype.kidsXmlFile = "";



 
dhtmlXGridObject.prototype.sortTreeRows = function(col,type,order){
 this._ls_col=col;
 this._ls_type=type;
 this._ls_order=order;

 var byParentHash = new Hashtable();
 for(var i=0;i<this.obj._rowslength();i++){
 if(byParentHash.get(this.obj._rows(i).parent_id)==null)
 byParentHash.put(this.obj._rows(i).parent_id,new dhtmlxArray());
}
 for(var i=0;i<this.obj._rowslength();i++){
 var tmpAr = byParentHash.get(this.obj._rows(i).parent_id);
 tmpAr[tmpAr.length] = this.obj._rows(i).idd 
 byParentHash.put(this.obj._rows(i).parent_id,tmpAr);
}


 var keysAr = byParentHash.keys;
 for(var j=0;j<keysAr.length;j++){
 var tmpAr = byParentHash.get(keysAr[j]);
 var ar = new Array();
 for(var i=0;i<tmpAr.length;i++){
 ar[i] = new Array();

 var a_val=this.cells(tmpAr[i],col).getValue().toString();
 if(type=='int'){
 ar[i][0]=parseFloat(a_val);
 ar[i][0]=isNaN(ar[i][0])?-99999999999999:ar[i][0];
}else
 ar[i][0] = a_val;

 ar[i][1] = this.getRowById(tmpAr[i])
 if((i!=0)&&(ar[i][0]!=ar[i-1][0]))ar._sort_me=true;
}

 
 if(ar._sort_me)
{
 if(type=='str')
 ar.sort(function(a,b){return(a[0]<b[0]?-1:(a[0]==b[0]?0:1))})

 if(type=='int')
 ar.sort(function(a,b){return(a[0]<b[0]?-1:(a[0]==b[0]?0:1))})

 if(type=='date'){
 try{
 ar.sort(function(a,b){return Date.parse(new Date(a[0]))-Date.parse(new Date(b[0]))})
}catch(er){
 alert('Incompatible date format.Sorted as string')
 ar.sort(function(a,b){return(a[0]<b[0]?-1:(a[0]==b[0]?0:1))})
}
}
}


 

 if(!dojo.render.html.khtml){
 var z=this.getRowById(keysAr[j]);
 if(z)z=z.rowIndex+1;
}
 else{
 var z=-1;
 for(var zkk=0;zkk<this.obj._rowslength();zkk++)
 if(this.obj._rows(zkk).idd==keysAr[j])
{z=zkk+1;break;}
}



 if((z<1)||(!z))var parentInd=0;
 else var parentInd=z-1;


 this._sortTreeRows(col,type,order,ar,parentInd);
}
}

dhtmlXGridObject.prototype._sortTreeRows = function(col,type,order,ar,parentInd){
 

 if(!dojo.render.html.khtml)
 var tb = this.obj.childNodes[0];
 else
 var tb = this.obj._rows(0).parentNode;

 if((order!='asc')&&(ar._sort_me))
 for(var i=0;i<ar.length;i++){
 if(tb.moveRow)
 tb.moveRow(this.rowsAr[ar[i][1].idd].rowIndex,parentInd+1)
 else
 if(this.obj._rows(parentInd))
{
 if(this.rowsAr[ar[i][1].idd]!=this.obj._rows(parentInd))
 tb.insertBefore(this.rowsAr[ar[i][1].idd],this.obj._rows(parentInd));
}
 else
 tb.appendChild(this.rowsAr[ar[i][1].idd]);}

 else
 for(var i=ar.length-1;i>=0;i--){
 if(tb.moveRow)
 tb.moveRow(this.rowsAr[ar[i][1].idd].rowIndex,parentInd+1);
 else
 if(this.obj._rows(parentInd))
{
 if(this.rowsAr[ar[i][1].idd]!=this.obj._rows(parentInd))
 tb.insertBefore(this.rowsAr[ar[i][1].idd],this.obj._rows(parentInd));
}
 else
 tb.appendChild(this.rowsAr[ar[i][1].idd]);}



 this.rowsCol=new dhtmlxArray();
 for(var i=0;i<this.obj._rowslength();i++)
 this.rowsCol[i]=this.obj._rows(i);
};

 
dhtmlXGridObject.prototype.has_kids_dec=function(pRow){
 if(!pRow)return;
 pRow.has_kids--;
 if(pRow.has_kids==0){
 pRow.expand=null;
 var treeCell = pRow.childNodes[this.cellType._dhx_find("tree")];
 treeCell.innerHTML = treeCell.innerHTML.replace(/\/plus|minus\.gif/,"/blank.gif").replace(/folderopen\.gif/gi,"folderclosed.gif");
}
 if((this._fake)&&(this._fake._realfake))
 this._fake.has_kids_dec(this._fake.rowsAr[pRow.idd],treeCell);
}

 
dhtmlXGridObject.prototype.has_kids_inc=function(pRow,treeCell){
 if(!pRow)return;
 if((!pRow.has_kids)||(pRow.has_kids==0)){
 pRow.has_kids=1;
 pRow.expand="no";
 pRow.childNodes[treeCell].innerHTML = pRow.childNodes[treeCell].innerHTML.replace(/\/blank\.gif/,"/plus.gif")
}
 else{
 pRow.has_kids++;
}
 if((this._fake)&&(this._fake._realfake))
 this._fake.has_kids_inc(this._fake.rowsAr[pRow.idd],treeCell);
}



 
eXcell_tree=function(cell){
 try{
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
}catch(er){}
/*
 this.edit = function(){
 if((this.er)||(this.grid._edtc))return;
 this.er=this.cell.childNodes[0];
 this.er=this.er.childNodes[this.er.childNodes.length-1];
 this.val=this.er.innerHTML;
 this.er.innerHTML="<textarea class='dhx_combo_edit' type='text' style='height:"+(this.cell.offsetHeight-6)+"px;width:100%;border:0px;margin:0px;padding:0px;padding-top:"+(dojo.render.html.moz?1:2)+"px;overflow:hidden;font-size:12px;font-family:Arial;'></textarea>";
 this.er.childNodes[0].onmousedown = function(e){(e||event).cancelBubble = true}
 this.er.childNodes[0].onselectstart=function(e){if(!e)e=event;e.cancelBubble=true;return true;};
 if(dojo.render.html.moz)this.er.style.top="1px";
 this.er.className+=" editable";
 this.er.firstChild.onclick = function(e){(e||event).cancelBubble = true};
 this.er.firstChild.value=this.val;
 this.er.firstChild.focus();
}
 */
 this.detach = function(){
 if(!this.er)return;
 this.er.innerHTML=this.er.firstChild.value;
 this.er.className=this.er.className.replace("editable","");
 var z=(this.val!=this.er.innerHMTL);
 if(dojo.render.html.moz)this.er.style.top="2px";
 this.er=null;
 return(z);
}
 this.getValue = function(){
 
 var kidsColl = this.cell.childNodes[0].childNodes;
 for(var i=0;i<kidsColl.length;i++){
 
 if(kidsColl[i].id=='nodeval')
 return kidsColl[i].innerHTML;
}
}
 
 this.setValueA = function(content){
 
 var kidsColl = this.cell.childNodes[0].childNodes;
 for(var i=0;i<kidsColl.length;i++){
 
 if(kidsColl[i].id=='nodeval')
 kidsColl[i].innerHTML=content;
}
}
 
 this.setImage = function(url){
 var z=this.cell.childNodes[0];
 var img=z.childNodes[z.childNodes.length-2];
 this.cell._aimage=url;
 ul=this.grid.imgURL+"/"+url;
 img.src=url;

}

 
 this.getImage = function(){
 return this.cell._aimage;
}

 
 this.setLabel = function(val){
 this.setValueA(val);
}

 
 this.getLabel = function(val){
 var kidsColl = this.cell.childNodes[0].childNodes;
 for(var i=0;i<kidsColl.length;i++){
 
 if(kidsColl[i].id=='nodeval')
 return kidsColl[i].innerHTML;
}
}

 
 this.setValue = function(valAr){
 if(typeof(valAr)!="object")
 valAr = valAr.split("^");

 this.cell.parentNode.parent_id = valAr[0];

 if((!this.grid.kidsXmlFile)&&(!this.grid._slowParse))valAr[2]=0;
 else
 this.cell.parentNode._xml_await=(valAr[2]!=0);

 this.cell.parentNode.has_kids = valAr[2];

 
 var pRow = this.grid.getRowById(valAr[0]);

 if(pRow==null){
 pRow = this.grid.loadedKidsHash.get("hashOfParents").get(valAr[0])
 
 
}

 

 var preStr = "";
 var node = "";
 if(pRow!=null){
 

 var level =(pRow.childNodes[cell._cellIndex].firstChild.childNodes.length-1)-1
 for(var i=0;i<level;i++)
 preStr+= "<span class='space'><img src='"+this.grid.imgURL+"blanc.gif' height='1px' class='space'></span>"

 this.grid.has_kids_inc(pRow,this.cell._cellIndex);
 
 if(pRow.expand!=""){
 
 this.grid.doOnRowAdded = function(row){
 if(row.has_kids>0){
 var parentsHash = this.loadedKidsHash.get("hashOfParents")
 parentsHash.put(row.idd,row)
 this.loadedKidsHash.put("hashOfParents",parentsHash)
}
 var kidsAr = this.loadedKidsHash.get(row.parent_id)
 if(kidsAr==null){
 var kidsAr = new dhtmlxArray(0)
}

 kidsAr[kidsAr.length] = row.parentNode.removeChild(row);
 this.rowsCol._dhx_removeAt(this.rowsCol._dhx_find(row));
 this.loadedKidsHash.put(row.parent_id,kidsAr)
 row._fhd=true;
 this.doOnRowAdded=function(){};

 var prow=this.rowsAr[row.parent_id];
 if(pRow._sumArr)
 for(var i=0;i<pRow.childNodes.length;i++)
 if(pRow.childNodes[i]._sumArr)
 this.cells4(pRow.childNodes[i]).setValueA(this._calcSCL(pRow.childNodes[i]));
}
}else{
 this.grid.doOnRowAdded = function(row){}
 pRow.childNodes[this.cell._cellIndex].innerHTML = pRow.childNodes[this.cell._cellIndex].innerHTML.replace(/\/plus\.gif/gi,"/minus.gif").replace(/folderclosed\.gif/gi,"folderopen.gif");
 var kidsAr = this.grid.loadedKidsHash.get(pRow.idd)

 if(this._dhkPos)
 kidsAr_dhx_insertAt(this._dhkPos,this.cell.parentNode);
 else
 kidsAr[kidsAr.length] = this.cell.parentNode;

 this.grid.loadedKidsHash.put(pRow.idd,kidsAr)
 this.doOnRowAdded=function(){};
}

}else{
 this.grid.doOnRowAdded = function(row){}
 preStr = "";
}

 
 if(valAr[2]!="" && valAr[2]!=0)
 node+="<img src='"+this.grid.imgURL+"plus.gif";
 else
 node+="<img src='"+this.grid.imgURL+"blank.gif";
 node+="' align='absmiddle' onclick='this."+(dojo.render.html.khtml?"":"parentNode.")+"parentNode.parentNode.parentNode.parentNode.grid.doExpand(this);event.cancelBubble=true;'>";
 

 node+="<img src='"+this.grid.imgURL+valAr[3]+"' align='absmiddle' "+(this.grid._img_height?(" height=\""+this.grid._img_height+"\""):"")+(this.grid._img_width?(" width=\""+this.grid._img_width+"\""):"")+" >";
 node+="<span "+(dojo.render.html.moz?"style='position:relative;top:2px;'":"")+"id='nodeval'>"+valAr[1]+"</span>"

 
 this.cell.innerHTML = "<div style=' overflow:hidden;white-space : nowrap;height:"+(dojo.render.html.ie?20:18)+"px;'>"+preStr+""+node+"</div>";

 this.cell._aimage=valAr[3];
 if(dojo.render.html.khtml)this.cell.vAlign="top";
 this.cell.parentNode.has_kids=0;
}
 
}
eXcell_tree.prototype = new eXcell;

 
dhtmlXGridObject.prototype._fixLevel=function(r2){
 var pRow=this.getRowById(r2.parent_id);

 var trcol=this.cellType._dhx_find("tree");

 this.has_kids_inc(pRow,trcol);

 if(pRow){
 pRow.childNodes[trcol].innerHTML = pRow.childNodes[trcol].innerHTML.replace(/\/plus\.gif/gi,"/minus.gif").replace(/folderopen\.gif/gi,"folderclosed.gif");
 pRow.expand = "";
}

 var preStr="";
 if(!pRow)var level=0;
 else
 var level =(pRow.childNodes[trcol].firstChild.childNodes.length-1)-1;
 for(var i=0;i<level;i++)
 preStr+= "<span class='space'><img src='' height='1' class='space'></span>"


 this._fixLevel2(r2,preStr,trcol);
};

 
dhtmlXGridObject.prototype._fixLevel2=function(r2,preStr,trcol){

 var z=r2.childNodes[trcol].firstChild.innerHTML;
 z=preStr+z.replace(/<(SPAN)[^>]*(><IMG)[^>]*(><\/SPAN>)/gi,"");
 r2.childNodes[trcol].firstChild.innerHTML=z;

 var a=this.loadedKidsHash.get(r2.idd);
 if(a){
 for(var i=0;i<a.length;i++)
 this._fixLevel2(a[i],preStr+"<span class='space'><img src='' height='1' class='space'></span>",trcol);
 this.loadedKidsHash.put(r2.idd,a);
}

};

 
dhtmlXGridObject.prototype._removeTrGrRow=function(node){
 var parent_id = node.parent_id
 this.collapseKids(node)
 
 
 var tmpAr = this.loadedKidsHash.get(parent_id)
 if(tmpAr!=null)
 tmpAr._dhx_removeAt(tmpAr._dhx_find(node))

 this.loadedKidsHash.remove(node.idd)
 
 var noda=node.nextSibling;
 this._removeTrGrRowRec(node.idd);

 pRow=this.getRowById(parent_id);
 if(!pRow)return;
 this.has_kids_dec(pRow);

 if(pRow._sumArr)
 for(var i=0;i<pRow.childNodes.length;i++)
 if(pRow.childNodes[i]._sumArr)
 this.cells4(pRow.childNodes[i]).setValueA(this._calcSCL(pRow.childNodes[i]));

}

 
dhtmlXGridObject.prototype._removeTrGrRowRec=function(id,inner){
 
 
 var newa=new Array();
 for(var i=0;i<this.rowsCol.length;i++)
 if(id==this.rowsCol[i].parent_id)
{
 newa[newa.length]=this.rowsCol[i].idd;
 this.rowsAr[this.rowsCol[i].idd] = null;
 this.rowsCol._dhx_removeAt(i);
 i--;
}
 if(newa.length)
 for(var i=0;i<newa.length;newa++)
 this._removeTrGrRowRec(newa[i],true);
}


 
dhtmlXGridObject.prototype._countBranchLength=function(ind){
 if(!this.rowsCol[ind+1])return 1;
 if(this.rowsCol[ind+1].parent_id!=this.rowsCol[ind].idd)return 1;
 var count=1;var i=1;
 while((this.rowsCol[ind+count])&&(this.rowsCol[ind+count].parent_id==this.rowsCol[ind].idd)){
 count+=this._countBranchLength(ind+count);
}
 return count;
}

 
dhtmlXGridObject.prototype.openItem=function(rowId){
 var x=this.getRowById(rowId);
 if(!x)return;
 this._openItem(x);
}


dhtmlXGridObject.prototype._openItem=function(x){
 var y=this.getRowById(x.parent_id);
 if(y)
 if(y.expand!="")this._openItem(y);
 this.expandKids(x);
}



dhtmlXGridObject.prototype._addRowClassic=dhtmlXGridObject.prototype.addRow;

 
dhtmlXGridObject.prototype.addRow=function(new_id,text,ind,parent_id,img,child){
 var trcol=this.cellType._dhx_find("tree");
 if(typeof(text)=="string")text=text.split(this.delim);
 var last_row=null;
 if((trcol!=-1)&&((text[trcol]||"").toString().search(/\^/gi)==-1)){
 var def=text[trcol];
 var d=(parent_id||"0").toString().split(",");
 for(var i=0;i<d.length;i++){
 text[trcol]=d[i]+"^"+def+"^"+(child?1:0)+"^"+(img||"folderOpen.gif");
 if(d[i]!=0)
 if((!ind)||(ind==0)){
 ind=this.getRowIndex(d[i]);
 if((ind!=-1)&&(this.rowsCol[ind].expand==""))ind+=this._countBranchLength(ind);
}
 
 last_row=this._addRowClassic(new_id,text,((!parent_id)&&(!ind)&&(ind!="0"))?window.undefined:ind);
}
 return last_row;
}

 return this._addRowClassic(new_id,text,ind);

}
dhtmlXGridObject.prototype.addRowBefore=function(new_id,text,sibl_id,img,child){
 var sb=this.rowsAr[sibl_id];
 if(!sb)return;

 var ind=this.getRowIndex(sibl_id);
 return this.addRow(new_id,text,ind,sb.parent_id,img,child);
}
dhtmlXGridObject.prototype.addRowAfter=function(new_id,text,sibl_id,img,child){
 var sb=this.rowsAr[sibl_id];
 if(!sb)return;
 var ind=this.getRowIndex(sibl_id);
 if((ind!=-1)&&(sb.expand==""))ind+=this._countBranchLength(ind);
 else ind++;
 return this.addRow(new_id,text,ind,sb.parent_id,img,child);
}




 

 
 
dhtmlXGridObject.prototype.enableSmartXMLParsing=function(mode){this._slowParse=convertStringToBoolean(mode);};


 
dhtmlXGridObject.prototype._seekAndDeploy=function(id){
 if((id=="null")||(!id))return;
 
 var a;

 for(a in this.rowsAr)
 if((this.rowsAr[a])&&(this.rowsAr[a]._xml)){
 var res=this.xmlLoader.doXPath("//row[@id=\""+id+"\"]",this.rowsAr[a]._xml[0].parentNode);
 if(res.length){
 
 res=res[0];
 var line=new Array();
 while(!this.rowsAr[res.getAttribute("id")]){
 line[line.length]=res.getAttribute("id");
 res=res.parentNode;
}
 line[line.length]=res.getAttribute("id");

 for(var i=line.length-1;i>0;i--){
 this._reParse(this.rowsAr[line[i]]);
 this._openItem(this.rowsAr[line[i]]);
}
 for(var i=1;i<line.length;i++)
 this.collapseKids(this.rowsAr[line[i]]);

 return this.getRowById(id);
}
}
};

 
dhtmlXGridObject.prototype._reParse=function(row){
 var row=this.rowsAr[row.idd];
 var ind=this.rowsCol._dhx_find(row);
 ind+=this._countBranchLength(ind);
 this._innerParse(row._xml,ind,this.cellType._dhx_find("tree"),row.idd);
 row.has_kids=row._xml_await=row._xml=null;
}

 


 
dhtmlXGridObject.prototype._copyTreeGridRowContent=function(frRow,from_row_id,to_row_id){
 var z=this.cellType._dhx_find("tree");
 for(i=0;i<frRow.cells.length;i++){
 if(i!=z)
 this.cells(to_row_id,i).setValue(this.cells(from_row_id,i).getValue())
 else
 this.cells(to_row_id,i).setValueA(this.cells(from_row_id,i).getValue())

}
}

 
dhtmlXGridObject.prototype.closeItem=function(rowId){
 var x=this.getRowById(rowId);
 if(!x)return;
 this.collapseKids(x);
}
 
dhtmlXGridObject.prototype.deleteChildItems=function(rowId){
 var w=this.getRowById(rowId);
 if(!w)return;
 this.expandKids(w);
 var x=this.loadedKidsHash.get(rowId);

 if(x)
{
 var z=x.length;
 for(var i=0;i<z;i++){
 this.deleteRow("",x[0]);
}
}
}
 
dhtmlXGridObject.prototype.getAllSubItems=function(rowId){
 var str="";
 var x=this.loadedKidsHash.get(rowId);
 if(x)
 for(var i=0;i<x.length;i++){
 if(str)str+=",";
 str+=x[i].idd;
 var z=this.getAllSubItems(x[i].idd);
 if((z)&&(str))str+=",";
 str+=z;
}

 return str;
}

 
dhtmlXGridObject.prototype.getChildItemIdByIndex=function(rowId,ind){
 var x=this.loadedKidsHash.get(rowId);
 if(!x)return null;
 return(x[ind]?x[ind].idd:null);
}

 
dhtmlXGridObject.prototype.getItemText=function(rowId){
 var x=this.getRowById(rowId);
 if(!x)return;
 var col=this.cellType._dhx_find("tree");
 var c = x.childNodes[col];
 var z=eval("new eXcell_"+this.cellType[col]+"(c)");
 return z.getValue();
}
 
dhtmlXGridObject.prototype.getLevel=function(rowId){
 var x=this.getRowById(rowId);
 if(!x)return;
 var level=0;
 while((x)&&(x.parent_id)){
 x=this.getRowById(x.parent_id);
 level++;
}
 return level;
}
 
dhtmlXGridObject.prototype.getOpenState=function(rowId){
 var x=this.getRowById(rowId);
 if(!x)return;
 if(x.expand=="")return true;
 return false;
}
 
dhtmlXGridObject.prototype.getParentId=function(rowId){
 var x=this.getRowById(rowId);
 if(!x)return null;
 return x.parent_id;
}
 
dhtmlXGridObject.prototype.getSubItems=function(rowId){
 var str=new Array();
 if(!rowId){
 for(var i=0;i<this.rowsCol.length;i++)
 if(!this.rowsCol[i].parent_id)
 str[str.length]=this.rowsCol[i].idd;
}else{
 var x=this.loadedKidsHash.get(rowId);
 if(x)
 for(var i=0;i<x.length;i++)
 str[str.length]=x[i].idd;
}
 return(str.length?str.join(","):"");
}


 
dhtmlXGridObject.prototype.expandAll=function(){
 for(var i=0;i<this.rowsCol.length;i++)
 if(this.rowsCol[i].parent_id)
 this.openItem(this.rowsCol[i].idd)
}
 
dhtmlXGridObject.prototype.collapseAll=function(rowId){
 for(var i=0;i<this.rowsCol.length;i++)
 if(this.rowsCol[i].parent_id)
 this.closeItem(this.rowsCol[i].idd)
}

 
dhtmlXGridObject.prototype.hasChildren=function(rowId){
 var x=this.loadedKidsHash.get(rowId);
 if(x)
 return x.length;
 if(this.getRowById(rowId)._xml_await)return -1;
 return 0;
}


 

dhtmlXGridObject.prototype.setItemCloseable=function(rowId,status){
 var x=this.getRowById(rowId);
 if(!x)return;
 x._closeable=(!convertStringToBoolean(status));
}
 
dhtmlXGridObject.prototype.setItemText=function(rowId,newtext){
 var x=this.getRowById(rowId);
 if(!x)return;
 var col=this.cellType._dhx_find("tree");
 var c = x.childNodes[col];
 var z=eval("new eXcell_"+this.cellType[col]+"(c)");
 z.setValueA(newtext);
}

 
dhtmlXGridObject.prototype.setItemText=function(rowId,newtext){
 var x=this.getRowById(rowId);
 if(!x)return;
 var col=this.cellType._dhx_find("tree");
 var c = x.childNodes[col];
 var z=eval("new eXcell_"+this.cellType[col]+"(c)");
 z.setValueA(newtext);
}

 
dhtmlXGridObject.prototype.setItemText=function(rowId,newtext){
 var x=this.getRowById(rowId);
 if(!x)return;
 var col=this.cellType._dhx_find("tree");
 var c = x.childNodes[col];
 var z=eval("new eXcell_"+this.cellType[col]+"(c)");
 z.setValueA(newtext);
}

 
dhtmlXGridObject.prototype.setItemImage=function(rowId,url){
 var x=this.getRowById(rowId);
 if(!x)return;
 var col=this.cellType._dhx_find("tree");
 var z = this.cells3(x,col);
 z.setImage(url);
}

 
dhtmlXGridObject.prototype.getItemImage=function(rowId){
 var x=this.getRowById(rowId);
 if(!x)return;
 var col=this.cellType._dhx_find("tree");
 if(col==-1)return "";
 var z = this.cells3(x,col);
 return z.getImage();
}


 
dhtmlXGridObject.prototype.setImageSize=function(width,height){
 this._img_width=width;
 this._img_height=height;
}


dhtmlXGridObject.prototype._getRowImage=function(row){
 return row.childNodes[this.cellType._dhx_find("tree")]._aimage;
}


 
 dhtmlXGridObject.prototype.setOnOpenStartHandler=function(func){if(typeof(func)=="function")this._spnFH=func;else this._spnFH=eval(func);};

 
 dhtmlXGridObject.prototype.setOnOpenEndHandler=function(func){if(typeof(func)=="function")this._epnFH=func;else this._epnFH=eval(func);};


 
 dhtmlXGridObject.prototype.setOnOpenEndHandler=function(func){if(typeof(func)=="function")this._epnFH=func;else this._epnFH=eval(func);};

 
 dhtmlXGridObject.prototype.enableTreeCellEdit=function(mode){
 this._edtc=!convertStringToBoolean(mode);
};


 

 dhtmlXGridObject.prototype._fixHiddenRowsAllTG=function(ind,state){
 for(i in this.rowsAr){
 if((this.rowsAr[i])&&(this.rowsAr[i].childNodes))
 this.rowsAr[i].childNodes[ind].style.display=state;
}
}

//====Rex.Sun@9:16 2007-4-10 Add : dhtmlXGrid_excell_link.js
/*
Copyright Scand LLC http://www.scbr.com
To use this component please contact info@scbr.com to obtain license

*/ 

 

eXcell_link = function(cell){
 this.cell = cell;
 this.grid = this.cell.parentNode.grid;
 this.edit = function(){}
 this.getValue = function(){
 if(this.cell.firstChild.getAttribute)
 return this.cell.firstChild.innerHTML+"^"+this.cell.firstChild.getAttribute("href")
 else
 return "";
}
 this.setValue = function(val){
 var valsAr = val.split("^");
 if(valsAr.length==1)
 valsAr[1] = "";
 else{
 if(valsAr.length>1){
 valsAr[1] = "href='"+valsAr[1]+"'";
 if(valsAr.length==3)
 valsAr[1]+= " target='"+valsAr[2]+"'";
 else
 valsAr[1]+= " target='_blank'";
}
}

 this.setCValue("<a "+valsAr[1]+" onclick='(isIE()?event:arguments[0]).cancelBubble = true;'>"+valsAr[0]+"</a>",valsAr);
}
}

eXcell_link.prototype = new eXcell;
eXcell_link.prototype.getTitle=function(){
 var z=this.cell.firstChild;
 return((z&&z.tagName)?z.getAttribute("href"):"");
}
eXcell_link.prototype.getContent=function(){
 var z=this.cell.firstChild;
 return((z&&z.tagName)?z.innerHTML:"");
}